Sha256: ebaa8c5342518aa50f8eb1195e6d7fec50630b681a1bc176bde5f26c1b267a3e

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 KB

Contents

module Timber
  module Events
    # The controller call event tracks controller invocations. For example, this line in Rails:
    #
    #   Processing by PagesController#home as HTML
    #
    # @note This event should be installed automatically through probes,
    #   such as the {Probes::ActionControllerLogSubscriber} probe.
    class ControllerCall < Timber::Event
      attr_reader :controller, :action, :params, :format

      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

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

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

      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
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
timber-1.0.13 lib/timber/events/controller_call.rb
timber-1.0.12 lib/timber/events/controller_call.rb
timber-1.0.11 lib/timber/events/controller_call.rb
timber-1.0.10 lib/timber/events/controller_call.rb
timber-1.0.9 lib/timber/events/controller_call.rb
timber-1.0.8 lib/timber/events/controller_call.rb
timber-1.0.7 lib/timber/events/controller_call.rb
timber-1.0.6 lib/timber/events/controller_call.rb
timber-1.0.5 lib/timber/events/controller_call.rb
timber-1.0.4 lib/timber/events/controller_call.rb
timber-1.0.3 lib/timber/events/controller_call.rb
timberio-1.0.3 lib/timber/events/controller_call.rb
timberio-1.0.2 lib/timber/events/controller_call.rb
timberio-1.0.1 lib/timber/events/controller_call.rb
timberio-1.0.0 lib/timber/events/controller_call.rb