Class: Remnant::Template::Trace
- Inherits:
-
Object
- Object
- Remnant::Template::Trace
- Defined in:
- lib/remnant/template/trace.rb
Instance Method Summary collapse
- #finished(template_name) ⇒ Object
-
#initialize ⇒ Trace
constructor
A new instance of Trace.
- #log(logger, rendering) ⇒ Object
- #root ⇒ Object
- #start(template_name) ⇒ Object
- #total_time ⇒ Object
Constructor Details
#initialize ⇒ Trace
Returns a new instance of Trace.
17 18 19 |
# File 'lib/remnant/template/trace.rb', line 17 def initialize @current = root end |
Instance Method Details
#finished(template_name) ⇒ Object
12 13 14 15 |
# File 'lib/remnant/template/trace.rb', line 12 def finished(template_name) @current.end_time = Time.now @current = @current.parent end |
#log(logger, rendering) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/remnant/template/trace.rb', line 29 def log(logger, rendering) rendering.results.map do |key, result| # line = Remnant.color line += "#{' ' * (result['depth'] - 1)}#{result['depth'] > 1 ? '└ ' : ''}" line += "#{result['time'].to_i}ms (#{result['exclusive'].to_i}ms)" line += Remnant.color(true) line += ' ' * ((line.size >= 50 ? 10 : 50 - line.size) - (result['depth'] == 1 ? 2 : 0)) line += "#{key}" logger.info line rendering.children.map do |child| log(logger, child) end end end |
#root ⇒ Object
25 26 27 |
# File 'lib/remnant/template/trace.rb', line 25 def root @root ||= Remnant::Template::Rendering.new('root') end |
#start(template_name) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/remnant/template/trace.rb', line 5 def start(template_name) rendering = Remnant::Template::Rendering.new(template_name) rendering.start_time = Time.now @current.add(rendering) @current = rendering end |
#total_time ⇒ Object
21 22 23 |
# File 'lib/remnant/template/trace.rb', line 21 def total_time root.child_time end |