Class: Rack::Insight::TemplatesPanel::Stats

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/rack/insight/panels/templates_panel/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

logger, verbose, verbosity

Constructor Details

#initialize(*args) ⇒ Stats

Returns a new instance of Stats.



10
11
12
13
# File 'lib/rack/insight/panels/templates_panel/stats.rb', line 10

def initialize(*args)
  @root = Rack::Insight::TemplatesPanel::Rendering.new(*args)
  @current = @root
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



8
9
10
# File 'lib/rack/insight/panels/templates_panel/stats.rb', line 8

def current
  @current
end

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/rack/insight/panels/templates_panel/stats.rb', line 8

def root
  @root
end

Instance Method Details

#begin_record!(rendering) ⇒ Object

Track when each template starts being rendered



16
17
18
19
# File 'lib/rack/insight/panels/templates_panel/stats.rb', line 16

def begin_record!(rendering)
  @current.add!(rendering) # Add the rendering as a child of the current and make rendering the new current
  @current = rendering
end

#finish!Object



29
30
31
32
# File 'lib/rack/insight/panels/templates_panel/stats.rb', line 29

def finish!
  @root.finish!(root._calculate_child_time)
  @current = nil
end

#finish_record!(timing) ⇒ Object

Track when each template finishes being rendered, move current back up the rendering chain



22
23
24
25
26
27
# File 'lib/rack/insight/panels/templates_panel/stats.rb', line 22

def finish_record!(timing)
  # This is the one being completed now, and for which we now know the timing duration
  @current.finish!(timing)
  # Prepare for the next template to finish
  @current = @current.parent
end

#to_sObject



34
35
36
# File 'lib/rack/insight/panels/templates_panel/stats.rb', line 34

def to_s
  "#{self.root.to_s}"
end