Sha256: 754d862a497e7c237a0708853e95be3dc97f3cc4ca2e4c61c6fdaac533cd83e7

Contents?: true

Size: 1015 Bytes

Versions: 5

Compression:

Stored size: 1015 Bytes

Contents

require "timber/event"

module Timber
  module Events
    # The template render event track template renderings and their performance.
    #
    # @note This event should be installed automatically through integrations,
    #   such as the {Integrations::ActionView::LogSubscriber} integration.
    class TemplateRender < Timber::Event
      attr_reader :message, :name, :time_ms

      def initialize(attributes)
        @message = attributes[:message] || raise(ArgumentError.new(":message is required"))
        @name = attributes[:name] || raise(ArgumentError.new(":name is required"))
        @time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required"))
        @time_ms = @time_ms.round(6)
      end

      def to_hash
        {name: name, time_ms: time_ms}
      end
      alias to_h to_hash

      # Builds a hash representation of containing simply objects, suitable for serialization.
      def as_json(_options = {})
        {:template_render => to_hash}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
timber-2.1.0.rc5 lib/timber/events/template_render.rb
timber-2.1.0.rc4 lib/timber/events/template_render.rb
timber-2.1.0.rc3 lib/timber/events/template_render.rb
timber-2.1.0.rc2 lib/timber/events/template_render.rb
timber-2.1.0.rc1 lib/timber/events/template_render.rb