class Identity
Definitions
def initialize(path, name = nil, line = nil, parent = nil, unique: true)
Signature
-
parameter
unique
Boolean | Symbol
Whether this identity is unique or needs a unique key/line number suffix.
Implementation
def initialize(path, name = nil, line = nil, parent = nil, unique: true)
@path = path
@name = name
@line = line
@parent = parent
@unique = unique
@key = nil
end
def scoped(locations = nil)
Given a set of locations, find the first one which matches this identity and return a new identity with the updated line number. This can be used to extract a location from a backtrace.
Implementation
def scoped(locations = nil)
if locations
# This code path is normally taken if we've got an exception with a backtrace:
locations.each do |location|
if location.path == @path
return self.with_line(location.lineno)
end
end
else
# In theory this should be a bit faster:
each_caller_location do |location|
if location.path == @path
return self.with_line(location.lineno)
end
end
end
return self
end