Sha256: c05de3043429c63ff2688bf919f1d7e8019e254f770c78a414424fb39f47bd1a

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

require 'peastash/middleware'
require 'active_support/notifications'

class Peastash
  class Railtie < ::Rails::Railtie
    config.peastash = ActiveSupport::OrderedOptions.new

    initializer 'peastash.configure' do |app|
      if app.config.peastash[:enabled]
        Peastash.with_instance.configure!(app.config.peastash)
        ActiveSupport::Notifications.subscribe('process_action.action_controller') do |name, started, finished, unique_id, data|
          # Handle parameters and sanitize if need be
          to_reject = [:db_runtime, :view_runtime, :exception]
          payload = data.reject { |key, _| to_reject.include?(key) }
          payload.merge!(db: data[:db_runtime], view: data[:view_runtime])
          payload.merge!(exception: { class: data[:exception].first, message: data[:exception].last[0..200] }) if data.has_key?(:exception)
          if Peastash.with_instance.configuration[:log_parameters]
            payload[:params].reject { |k, _| ActionController::LogSubscriber::INTERNAL_PARAMS.include?(k) }
          else
            payload.delete(:params)
          end
          # Preserve explicitely set data
          Peastash.with_instance.store.merge!(payload) { |key, old_val, new_val| old_val }
        end
        before_middleware = app.config.peastash[:insert_before] || ActionDispatch::ShowExceptions
        app.config.middleware.insert_before before_middleware, Peastash::Middleware
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
peastash-0.2.2 lib/peastash/rails_ext/railtie.rb
peastash-0.2.1 lib/peastash/rails_ext/railtie.rb
peastash-0.1.1 lib/peastash/rails_ext/railtie.rb
peastash-0.1.0 lib/peastash/rails_ext/railtie.rb
peastash-0.0.9 lib/peastash/rails_ext/railtie.rb
peastash-0.0.8 lib/peastash/rails_ext/railtie.rb