Sha256: 0d8a76fa52321be121b68dbb796bd5d5c4d73a7f93b885c53b49ca5acb78af7c

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 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::Const::PUMA_VERSION)
      BetterErrors.binding_of_caller_available && Puma::Const::PUMA_VERSION.split(".").first.to_i == 3
    end

    def app
      Rails.application
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
debug-extras-0.3.6 lib/debug_extras/railtie.rb
debug-extras-0.3.5 lib/debug_extras/railtie.rb
debug-extras-0.3.4 lib/debug_extras/railtie.rb
debug-extras-0.3.3 lib/debug_extras/railtie.rb