Sha256: 93ca221117a1e0f4a60375d66ba42530977e3165301d8558695fca64074bbd1c

Contents?: true

Size: 1.67 KB

Versions: 16

Compression:

Stored size: 1.67 KB

Contents

module Rack::Insight
  class TemplatesPanel

    class Rendering

      include Rack::Insight::MagicInsight

      attr_accessor :template
      attr_accessor :partial
      attr_accessor :parent
      attr_reader :children

      # '_' prevents MagicInsight template from calling the method
      # Time tracking
      attr_accessor :_time, :_exclusive_time, :_child_time

      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

      # called from Stats#begin_record
      def add!(rendering)
        @children << rendering
        rendering.parent = self
      end

      # LOL what?
      #def delete(rendering)
      #  @children.delete(rendering)
      #end

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

      def _calculate_exclusive_time
        _time - _child_time
      end

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

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

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

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

    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rack-insight-0.6.4 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.6.3 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.6.2 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.30 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.29 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.28 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.27 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.26 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.25 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.24 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.23 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.22 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.21 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.20 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.19 lib/rack/insight/panels/templates_panel/rendering.rb
rack-insight-0.5.18 lib/rack/insight/panels/templates_panel/rendering.rb