Sha256: 6b0326ce485673d68acc188d6dd86f2ed0063aa64759e9d67c4c6452b41df819

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

module Airbrake
  module Rails
    # ActionControllerRouteSubscriber sends route stat information, including
    # performance data.
    #
    # @since v8.0.0
    class ActionControllerRouteSubscriber
      def initialize
        @all_routes = nil
      end

      def call(*args)
        # We cannot move this to #initialize because Rails initializes routes
        # after hooks.
        @all_routes ||= find_all_routes

        event = ActiveSupport::Notifications::Event.new(*args)
        payload = event.payload

        key = find_route(payload[:params])
        Airbrake::Rack::RequestStore[:routes][key] = payload[:method]
      end

      private

      def find_route(params)
        @all_routes.each do |r|
          if r.defaults[:controller] == params['controller'] &&
             r.defaults[:action] == params['action']
            return r.path.spec.to_s
          end
        end
      end

      # Finds all routes that the app supports, including engines.
      def find_all_routes
        routes = [*::Rails.application.routes.routes.routes]
        ::Rails::Engine.subclasses.each do |engine|
          routes.push(*engine.routes.routes.routes)
        end
        routes
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
airbrake-8.1.3 lib/airbrake/rails/action_controller_route_subscriber.rb