Class: Rack::Insight::TemplatesPanel::Rendering

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

Constant Summary

Constants included from MagicInsight

MagicInsight::ANCESTORS_FILTER, MagicInsight::IDIOMS, MagicInsight::SAFETY_REGEX_FILTER, MagicInsight::WARNING

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MagicInsight

#_dirty_ancestors, #_dirty_methods, #_filtered_ancestors, #_filtered_methods, #_has_idioms?, #_idiomatic_method, #_idiomatic_methods, #_magic_insight_methods, #_my_children, #_sorted_methods, included

Constructor Details

#initialize(template) ⇒ Rendering

Returns a new instance of Rendering.



17
18
19
20
21
22
23
24
25
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 17

def initialize(template)
  @template = template.to_s
  @partial = template.partial ? 'yes' : 'no' if template.respond_to?(:partial)
  @_time = 0
  @_exclusive_time = 0
  @_child_time = 0
  @children = []
  @parent = nil
end

Instance Attribute Details

#_child_timeObject

‘_’ prevents MagicInsight template from calling the method Time tracking



15
16
17
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 15

def _child_time
  @_child_time
end

#_exclusive_timeObject

‘_’ prevents MagicInsight template from calling the method Time tracking



15
16
17
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 15

def _exclusive_time
  @_exclusive_time
end

#_timeObject

‘_’ prevents MagicInsight template from calling the method Time tracking



15
16
17
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 15

def _time
  @_time
end

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#partialObject

Returns the value of attribute partial.



9
10
11
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 9

def partial
  @partial
end

#templateObject

Returns the value of attribute template.



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

def template
  @template
end

Instance Method Details

#_calculate_child_timeObject



48
49
50
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 48

def _calculate_child_time
  children.inject(0.0) { |memo, c| memo + c._time } || 0
end

#_calculate_exclusive_timeObject



44
45
46
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 44

def _calculate_exclusive_time
  _time - _child_time
end

#_human_time(t = self._time) ⇒ Object



52
53
54
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 52

def _human_time(t = self._time)
  "%.2fms" % t
end

#add!(rendering) ⇒ Object

called from Stats#begin_record



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

def add!(rendering)
  @children << rendering
  rendering.parent = self
end

#finish!(timing) ⇒ Object

LOL what? def delete(rendering)

@children.delete(rendering)

end



38
39
40
41
42
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 38

def finish!(timing)
  self._time = timing || 0
  self._child_time = _calculate_child_time
  self._exclusive_time = _calculate_exclusive_time
end

#time_summaryObject



56
57
58
59
60
61
62
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 56

def time_summary
  if children.any?
    "#{_human_time}, (exclusive: #{_human_time(_exclusive_time)}, child: #{_human_time(_child_time)})"
  else
    _human_time
  end
end

#to_sObject



64
65
66
# File 'lib/rack/insight/panels/templates_panel/rendering.rb', line 64

def to_s
  "#{template} (#{time_summary})#{!children.empty? ? " (#{children.length} children)\n#{children.map {|x| x.to_s}.join("\n")}" : ''}"
end