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 integrations, such as the Integrations::ActionController::LogSubscriber integration.

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

Processing by PagesController#home as HTML

Constant Summary collapse

PARAMS_JSON_MAX_BYTES =
32_768.freeze
PASSWORD_NAME =
'password'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ControllerCall

Returns a new instance of ControllerCall.



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

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

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



16
17
18
# File 'lib/timber/events/controller_call.rb', line 16

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



16
17
18
# File 'lib/timber/events/controller_call.rb', line 16

def controller
  @controller
end

#formatObject (readonly)

Returns the value of attribute format.



16
17
18
# File 'lib/timber/events/controller_call.rb', line 16

def format
  @format
end

#paramsObject (readonly)

Returns the value of attribute params.



16
17
18
# File 'lib/timber/events/controller_call.rb', line 16

def params
  @params
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/controller_call.rb', line 31

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

#messageObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/timber/events/controller_call.rb', line 35

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



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

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