Class: Rack::Bug::TemplatesPanel::Rendering
- Inherits:
-
Object
- Object
- Rack::Bug::TemplatesPanel::Rendering
- Defined in:
- lib/rack/bug/panels/templates_panel/rendering.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#start_time ⇒ Object
(also: #time)
Returns the value of attribute start_time.
Instance Method Summary collapse
- #add(rendering) ⇒ Object
- #child_duration ⇒ Object
- #children_html ⇒ Object
- #delete(rendering) ⇒ Object
- #duration ⇒ Object
- #duration_summary ⇒ Object
- #exclusive_duration ⇒ Object
- #html ⇒ Object
-
#initialize(name, start_time = nil, end_time = nil) ⇒ Rendering
constructor
A new instance of Rendering.
- #joined_children_html ⇒ Object
Constructor Details
#initialize(name, start_time = nil, end_time = nil) ⇒ Rendering
Returns a new instance of Rendering.
13 14 15 16 17 18 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 13 def initialize(name, start_time = nil, end_time = nil) @name = name @start_time = start_time || Time.now @end_time = end_time @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
11 12 13 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 11 def children @children end |
#end_time ⇒ Object
Returns the value of attribute end_time.
9 10 11 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 9 def end_time @end_time end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 6 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 10 def parent @parent end |
#start_time ⇒ Object Also known as: time
Returns the value of attribute start_time.
7 8 9 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 7 def start_time @start_time end |
Instance Method Details
#add(rendering) ⇒ Object
20 21 22 23 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 20 def add(rendering) @children << rendering rendering.parent = self end |
#child_duration ⇒ Object
41 42 43 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 41 def child_duration children.inject(0.0) { |memo, c| memo + c.duration } end |
#children_html ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 62 def children_html return "" unless children.any? <<-HTML <ul>#{joined_children_html}</ul> HTML end |
#delete(rendering) ⇒ Object
25 26 27 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 25 def delete(rendering) @children.delete(rendering) end |
#duration ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 29 def duration if @end_time @end_time - @start_time else child_duration end end |
#duration_summary ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 45 def duration_summary if children.any? "%.2fms, %.2f exclusive" % [duration * 1_000, exclusive_duration * 1_000] else "%.2fms" % (duration * 1_000) end end |
#exclusive_duration ⇒ Object
37 38 39 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 37 def exclusive_duration duration - child_duration end |
#html ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 52 def html <<-HTML <li> <p>#{name} (#{duration_summary})</p> #{children_html} </li> HTML end |
#joined_children_html ⇒ Object
70 71 72 |
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 70 def joined_children_html children.map { |c| c.html }.join end |