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 integration.
The controller call event tracks controller invocations. For example, this line in Rails:
Processing by PagesController#home as HTML
Constant Summary collapse
- ACTION_MAX_BYTES =
256.freeze
- FORMAT_MAX_BYTES =
256.freeze
- CONTROLLER_MAX_BYTES =
256.freeze
- 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.
21 22 23 24 25 26 27 |
# File 'lib/timber/events/controller_call.rb', line 21 def initialize(attributes) normalizer = Util::AttributeNormalizer.new(attributes) @controller = normalizer.fetch!(:controller, :string, :limit => CONTROLLER_MAX_BYTES) @action = normalizer.fetch!(:action, :string, :limit => ACTION_MAX_BYTES) @params = normalizer.fetch(:params, :hash, :sanitize => [PASSWORD_NAME]) @format = normalizer.fetch(:format, :string, :limit => FORMAT_MAX_BYTES) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
19 20 21 |
# File 'lib/timber/events/controller_call.rb', line 19 def action @action end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
19 20 21 |
# File 'lib/timber/events/controller_call.rb', line 19 def controller @controller end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
19 20 21 |
# File 'lib/timber/events/controller_call.rb', line 19 def format @format end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
19 20 21 |
# File 'lib/timber/events/controller_call.rb', line 19 def params @params end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
39 40 41 |
# File 'lib/timber/events/controller_call.rb', line 39 def as_json( = {}) {:controller_call => to_hash} end |
#message ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/timber/events/controller_call.rb', line 43 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
29 30 31 32 33 34 35 |
# File 'lib/timber/events/controller_call.rb', line 29 def to_hash @to_hash ||= Util::NonNilHashBuilder.build do |h| h.add(:controller, controller) h.add(:action, action) h.add(:params_json, params.to_json.byteslice(0, PARAMS_JSON_MAX_BYTES)) end end |