Sha256: a36a385f526fd0923d31509db1ca2cd56fee1bda494e9f19494e49dce9552b3f

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Timber
  module Probes
    # Wraps process_action so that we get *anu* logs written within the controller.
    # This is superior to using process_action in ActionController::LogSubscriber.
    class ActionControllerBase < Probe
      module InstanceMethods
        def process(*args)
          request_context      = Contexts::HTTPRequests::ActionControllerSpecific.new(self)
          organization_context = Contexts::Organizations::ActionController.new(self)
          user_context         = Contexts::Users::ActionController.new(self)
          response_context     = Contexts::HTTPResponses::ActionController.new(self)
          # The order is relevant here, request_context is higher in the hierarchy
          CurrentContext.add(request_context, organization_context, user_context, response_context) do
            super
          end
        end
      end

      def initialize
        require "action_controller"
      rescue LoadError => e
        raise RequirementNotMetError.new(e.message)
      end

      def insert!
        return true if ::ActionController::Base.include?(InstanceMethods)
        ::ActionController::Base.send(:include, InstanceMethods)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timberio-1.0.0.beta1 lib/timber/probes/action_controller_base.rb