Class: Rodauth::Rails::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rodauth/rails/middleware.rb

Overview

Middleware that’s added to the Rails middleware stack. Normally the main Roda app could be used directly, but this trick allows the app class to be reloadable.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
# File 'lib/rodauth/rails/middleware.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#asset_request?(env) ⇒ Boolean

Check whether it’s a request to an asset managed by Sprockets or Propshaft.

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/rodauth/rails/middleware.rb', line 23

def asset_request?(env)
  return false unless ::Rails.configuration.respond_to?(:assets)

  env["PATH_INFO"] =~ %r(\A/{0,2}#{::Rails.configuration.assets.prefix})
end

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/rodauth/rails/middleware.rb', line 11

def call(env)
  return @app.call(env) if asset_request?(env)

  app = Rodauth::Rails.app.new(@app)

  # allow the Rails app to call Rodauth methods that throw :halt
  catch(:halt) do
    app.call(env)
  end
end