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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ TemplateRender

Returns a new instance of TemplateRender.



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

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

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/timber/events/template_render.rb', line 10

def message
  @message
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/timber/events/template_render.rb', line 10

def name
  @name
end

#time_msObject (readonly)

Returns the value of attribute time_ms.



10
11
12
# File 'lib/timber/events/template_render.rb', line 10

def time_ms
  @time_ms
end

Instance Method Details

#as_json(_options = {}) ⇒ Object

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



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

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

#to_hashObject Also known as: to_h



19
20
21
# File 'lib/timber/events/template_render.rb', line 19

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