Class: Rack::Bug::TemplatesPanel::Rendering

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bug/panels/templates_panel/rendering.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#childrenObject (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_timeObject

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

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 6

def name
  @name
end

#parentObject

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_timeObject 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_durationObject



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_htmlObject



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

#durationObject



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_summaryObject



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_durationObject



37
38
39
# File 'lib/rack/bug/panels/templates_panel/rendering.rb', line 37

def exclusive_duration
  duration - child_duration
end

#htmlObject



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_htmlObject



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