Class: AccountMiddleware
- Inherits:
-
Object
- Object
- AccountMiddleware
- Defined in:
- lib/generators/authentication/templates/lib/account_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ AccountMiddleware
constructor
A new instance of AccountMiddleware.
Constructor Details
#initialize(app) ⇒ AccountMiddleware
Returns a new instance of AccountMiddleware.
2 3 4 |
# File 'lib/generators/authentication/templates/lib/account_middleware.rb', line 2 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/generators/authentication/templates/lib/account_middleware.rb', line 6 def call(env) request = ActionDispatch::Request.new(env) if m = /\A(\/(\d{1,}))/.match(request.path_info) script_name, account_id, path_info = [m[1], m[2], m.post_match] request.script_name = script_name request.path_info = path_info.presence || "/" set_current_account(account_id) @app.call(request.env) else @app.call(request.env) end end |