Class: CodeMapper::Filter::MaxDepth

Inherits:
Object
  • Object
show all
Defined in:
lib/code_mapper/filter/max_depth.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_depth) ⇒ MaxDepth

Returns a new instance of MaxDepth.



4
5
6
7
# File 'lib/code_mapper/filter/max_depth.rb', line 4

def initialize(max_depth)
  @max_depth = max_depth
  @depth = 0
end

Instance Method Details

#keep?(tp, _) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/code_mapper/filter/max_depth.rb', line 9

def keep?(tp, _)
  if call_event?(tp)
    @depth += 1
    return false if @depth > @max_depth
  elsif return_event?(tp)
    old_depth = @depth
    @depth -= 1
    return false if old_depth > @max_depth
  end

  true
end