Class: ScoutApm::LayerDepthFirstWalker

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/layer_converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_layer) ⇒ LayerDepthFirstWalker

Returns a new instance of LayerDepthFirstWalker.



180
181
182
# File 'lib/scout_apm/layer_converter.rb', line 180

def initialize(root_layer)
  @root_layer = root_layer
end

Instance Attribute Details

#root_layerObject (readonly)

Returns the value of attribute root_layer.



178
179
180
# File 'lib/scout_apm/layer_converter.rb', line 178

def root_layer
  @root_layer
end

Instance Method Details

#after(&block) ⇒ Object



188
189
190
# File 'lib/scout_apm/layer_converter.rb', line 188

def after(&block)
  @after_block = block
end

#before(&block) ⇒ Object



184
185
186
# File 'lib/scout_apm/layer_converter.rb', line 184

def before(&block)
  @before_block = block
end

#walk(layer = root_layer, &block) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/scout_apm/layer_converter.rb', line 192

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