Sha256: 3fb388214a8f6d6cb478895ca618d83a46254ee8337d1dd9c8cdcd5daf4b744e

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'caliper/rails/instrumentation'
require 'caliper/rails/append_info'

module Caliper
  class Railtie < ::Rails::Railtie
    rake_tasks do
      load "caliper/tasks/caliper.rake"
    end

    config.caliper = ActiveSupport::OrderedOptions.new

    initializer "caliper.initialize" do |app|
      app.middleware.use Caliper::Rack

      ActiveSupport.on_load(:action_controller) do
        ActionController::Base.send(:include, Caliper::Rails::AppendInfo)
      end

      ActiveSupport::Notifications.subscribe(/(^render|action_controller|active_record)/) do |*args|
        event = ActiveSupport::Notifications::Event.new(*args)

        # set this so that sql and view notifications has access to caliper tracer
        if event.name == 'start_processing.action_controller'
          @caliper_tracer = event.payload[:caliper_tracer]
        end

        @caliper_tracer.record(event) if @caliper_tracer
      end

    end

    # update routes to Caliper
    config.after_initialize do
      ::Rails.application.reload_routes!
      inspector = Caliper::RouteInspector.new
      all_routes = ::Rails.application.routes.routes
      CaliperApi.update_routes(
        Yajl::Encoder.encode({"routes" => inspector.routes(all_routes)})
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
caliper-0.0.2 lib/caliper/railtie.rb
caliper-0.0.1 lib/caliper/railtie.rb