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

PASSWORD_NAME =
'password'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ControllerCall

Returns a new instance of ControllerCall.



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

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.



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

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



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

def controller
  @controller
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



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

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

#messageObject



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

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



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

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