Sha256: 40ff82dea216781ebaa42dd1221067a5d01baf5645a6a5e090a76fd2b25d9c27

Contents?: true

Size: 845 Bytes

Versions: 3

Compression:

Stored size: 845 Bytes

Contents

module Ahoy
  class Engine < ::Rails::Engine
    # from https://github.com/evrone/quiet_assets/blob/master/lib/quiet_assets.rb
    initializer "ahoy", after: "sprockets.environment" do |app|
      next unless Ahoy.quiet

      # Parse PATH_INFO by assets prefix
      AHOY_PREFIX = "/ahoy/"
      KEY = "ahoy.old_level"

      # Just create an alias for call in middleware
      Rails::Rack::Logger.class_eval do
        def call_with_quiet_ahoy(env)
          begin
            if env["PATH_INFO"].start_with?(AHOY_PREFIX)
              env[KEY] = Rails.logger.level
              Rails.logger.level = Logger::ERROR
            end
            call_without_quiet_ahoy(env)
          ensure
            Rails.logger.level = env[KEY] if env[KEY]
          end
        end
        alias_method_chain :call, :quiet_ahoy
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ahoy_matey-0.3.2 lib/ahoy/engine.rb
ahoy_matey-0.3.1 lib/ahoy/engine.rb
ahoy_matey-0.3.0 lib/ahoy/engine.rb