Sha256: 37611555aa0870d19adae4ba10b749bb49640847a663eee3be193ef28d51a083

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require "debug_extras/middleware/debug"
require "debug_extras/middleware/fast_better_errors"

module DebugExtras
  class Railtie < Rails::Railtie
    initializer "debug_extras.configure_rails_initialization" do
      if Rails.env.development?
        insert_middleware(DebugExtras::Debug)
        insert_middleware(DebugExtras::FastBetterErrors) if better_errors_slow?
      end
    end

    private

    def insert_middleware(middleware)
      if defined? BetterErrors::Middleware
        app.middleware.insert_before ActionDispatch::Reloader, middleware
      elsif defined? ActionDispatch::DebugExceptions
        app.middleware.insert_after ActionDispatch::DebugExceptions, middleware
      else
        app.middleware.use middleware
      end
    end

    def better_errors_slow?
      return false unless defined? BetterErrors && defined? Puma
      BetterErrors.binding_of_caller_available && [Rails.version, Puma::Const::PUMA_VERSION].map(&:to_i) == [5, 3]
    end

    def app
      Rails.application
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
debug-extras-0.3.2 lib/debug_extras/railtie.rb