Class: Timber::Events::ControllerCall
- Inherits:
-
Timber::Event
- Object
- Timber::Event
- Timber::Events::ControllerCall
- Defined in:
- lib/timber/events/controller_call.rb
Overview
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
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
-
#initialize(attributes) ⇒ ControllerCall
constructor
A new instance of ControllerCall.
- #message ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
16 17 18 |
# File 'lib/timber/events/controller_call.rb', line 16 def action @action end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
16 17 18 |
# File 'lib/timber/events/controller_call.rb', line 16 def controller @controller end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
16 17 18 |
# File 'lib/timber/events/controller_call.rb', line 16 def format @format end |
#params ⇒ Object (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( = {}) {:controller_call => to_hash} end |
#message ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/timber/events/controller_call.rb', line 35 def = "Processing by #{controller}##{action}" if !.nil? << " as #{format}" end if !params.nil? && params.length > 0 << "\n Parameters: #{params.inspect}" end end |
#to_hash ⇒ Object 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 |