Class: Timber::Events::ControllerCall

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

Overview

Note:

This event should be installed automatically through probes, such as the Probes::ActionControllerLogSubscriber probe.

The controller call event tracks controller invocations. For example, this line in Rails:

Processing by PagesController#home as HTML

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ControllerCall

Returns a new instance of ControllerCall.



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

def initialize(attributes)
  @controller = attributes[:controller] || raise(ArgumentError.new(":controller is required"))
  @action = attributes[:action] || raise(ArgumentError.new(":action is required"))
  @params = attributes[:params]
  @format = attributes[:format]
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



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

def controller
  @controller
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



24
25
26
# File 'lib/timber/events/controller_call.rb', line 24

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

#messageObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/timber/events/controller_call.rb', line 28

def message
  message = "Processing by #{controller}##{action}"
  if !message.nil?
    message << " as #{format}"
  end
  if !params.nil? && params.length > 0
    message << "\n  Parameters: #{params.inspect}"
  end
  message
end

#to_hashObject Also known as: to_h



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

def to_hash
  {controller: controller, action: action}
end