Module: Diecut::CallerLocationsPolyfill

Included in:
PluginDescription
Defined in:
lib/diecut/caller-locations-polyfill.rb

Defined Under Namespace

Classes: FakeLocation

Constant Summary collapse

LINE_RE =
%r[(?<absolute_path>[^:]):(?<lineno>\d+):(?:in `(?<label>[^'])')?]

Instance Method Summary collapse

Instance Method Details

#caller_locations(range, length = nil) ⇒ Object

covers exactly the use cases we need



8
9
10
11
12
13
14
# File 'lib/diecut/caller-locations-polyfill.rb', line 8

def caller_locations(range, length=nil)
  caller[range.begin+1..range.end+1].map do |line|
    if m = LINE_RE.match(line)
      FakeLocation.new(m.named_captures.values_at("absolute_path", "lineno", "label"))
    end
  end
end