Class: ScoutApm::LayerConverters::DepthFirstWalker
- Inherits:
-
Object
- Object
- ScoutApm::LayerConverters::DepthFirstWalker
- Defined in:
- lib/scout_apm/layer_converters/depth_first_walker.rb
Instance Attribute Summary collapse
-
#root_layer ⇒ Object
readonly
Returns the value of attribute root_layer.
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
-
#initialize(root_layer) ⇒ DepthFirstWalker
constructor
A new instance of DepthFirstWalker.
- #walk(layer = root_layer, &block) ⇒ Object
Constructor Details
#initialize(root_layer) ⇒ DepthFirstWalker
Returns a new instance of DepthFirstWalker.
6 7 8 |
# File 'lib/scout_apm/layer_converters/depth_first_walker.rb', line 6 def initialize(root_layer) @root_layer = root_layer end |
Instance Attribute Details
#root_layer ⇒ Object (readonly)
Returns the value of attribute root_layer.
4 5 6 |
# File 'lib/scout_apm/layer_converters/depth_first_walker.rb', line 4 def root_layer @root_layer end |
Instance Method Details
#after(&block) ⇒ Object
14 15 16 |
# File 'lib/scout_apm/layer_converters/depth_first_walker.rb', line 14 def after(&block) @after_block = block end |
#before(&block) ⇒ Object
10 11 12 |
# File 'lib/scout_apm/layer_converters/depth_first_walker.rb', line 10 def before(&block) @before_block = block end |
#walk(layer = root_layer, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/scout_apm/layer_converters/depth_first_walker.rb', line 18 def walk(layer=root_layer, &block) # Need to run this for the root layer the first time through. if layer == root_layer @before_block.call(layer) if @before_block yield layer @after_block.call(layer) if @after_block end layer.children.each do |child| @before_block.call(child) if @before_block yield child walk(child, &block) @after_block.call(child) if @after_block end nil end |