Class: Timber::Events::TemplateRender

Inherits:
Timber::Event
  • Object
show all
Defined in:
lib/timber/events/template_render.rb

Overview

Note:

This event should be installed automatically through integrations, such as the Integrations::ActionView::LogSubscriber integration.

The template render event track template renderings and their performance.

Constant Summary collapse

MESSAGE_MAX_BYTES =
8192.freeze
NAME_MAX_BYTES =
1024.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ TemplateRender

Returns a new instance of TemplateRender.



15
16
17
18
19
20
# File 'lib/timber/events/template_render.rb', line 15

def initialize(attributes)
  normalizer = Util::AttributeNormalizer.new(attributes)
  @message = normalizer.fetch!(:message, :string, :limit => MESSAGE_MAX_BYTES)
  @name = normalizer.fetch!(:name, :string, :limit => NAME_MAX_BYTES)
  @time_ms = normalizer.fetch!(:time_ms, :float, :precision => 6)
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



13
14
15
# File 'lib/timber/events/template_render.rb', line 13

def message
  @message
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/timber/events/template_render.rb', line 13

def name
  @name
end

#time_msObject (readonly)

Returns the value of attribute time_ms.



13
14
15
# File 'lib/timber/events/template_render.rb', line 13

def time_ms
  @time_ms
end

Instance Method Details

#as_json(_options = {}) ⇒ Object

Builds a hash representation containing simple objects, suitable for serialization (JSON).



31
32
33
# File 'lib/timber/events/template_render.rb', line 31

def as_json(_options = {})
  {:template_render => to_hash}
end

#to_hashObject Also known as: to_h



22
23
24
25
26
27
# File 'lib/timber/events/template_render.rb', line 22

def to_hash
  @to_hash ||= Util::NonNilHashBuilder.build do |h|
    h.add(:name, name)
    h.add(:time_ms, time_ms)
  end
end