class ScoutApm::LayerConverters::DepthFirstWalker
Attributes
root_layer[R]
Public Class Methods
new(root_layer)
click to toggle source
# File lib/scout_apm/layer_converters/depth_first_walker.rb, line 6 def initialize(root_layer) @root_layer = root_layer @on_blocks = [] @before_blocks = [] @after_blocks = [] end
Public Instance Methods
after(&block)
click to toggle source
# File lib/scout_apm/layer_converters/depth_first_walker.rb, line 18 def after(&block) @after_blocks << block end
before(&block)
click to toggle source
# File lib/scout_apm/layer_converters/depth_first_walker.rb, line 14 def before(&block) @before_blocks << block end
on(&block)
click to toggle source
# File lib/scout_apm/layer_converters/depth_first_walker.rb, line 22 def on(&block) @on_blocks << block end
walk(layer=root_layer)
click to toggle source
# File lib/scout_apm/layer_converters/depth_first_walker.rb, line 26 def walk(layer=root_layer) # Need to run this for the root layer the first time through. if layer == root_layer @before_blocks.each{|b| b.call(layer) } @on_blocks.each{|b| b.call(layer) } end layer.children.each do |child| @before_blocks.each{|b| b.call(child) } @on_blocks.each{|b| b.call(child) } walk(child) @after_blocks.each{|b| b.call(child) } end if layer == root_layer @after_blocks.each{|b| b.call(layer) } end nil end