Class: Logue::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/logue/locations/stack.rb

Constant Summary collapse

FILTER_RE =
Regexp.new 'logue.*/lib/logue'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth: 2) ⇒ Stack

Returns a new instance of Stack.



9
10
11
12
13
14
15
16
# File 'lib/logue/locations/stack.rb', line 9

def initialize depth: 2
  # caller_locations requires Ruby 2.0+
  locations = caller_locations depth
  @frames = locations&.collect do |loc|
    # no absolute_path from "(eval)"
    Frame.new path: loc.absolute_path || loc.path, line: loc.lineno, method: loc.label
  end
end

Instance Attribute Details

#framesObject (readonly)

Returns the value of attribute frames.



7
8
9
# File 'lib/logue/locations/stack.rb', line 7

def frames
  @frames
end

Instance Method Details

#filteredObject



18
19
20
21
# File 'lib/logue/locations/stack.rb', line 18

def filtered
  logframe = @frames.rindex { |frm| frm.path.index FILTER_RE }
  @frames[logframe + 1 .. -1]
end