Class: RequestStoreRails::Middleware
- Inherits:
-
Object
- Object
- RequestStoreRails::Middleware
- Defined in:
- lib/request_store_rails/middleware.rb
Overview
Public: Middleware that takes care of setting a thread-local variable, which enables RequestLocals to associate threads with the store for a request.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Internal: Assigns a thread-local variable to identify the current store, and cleans up all the variables stored for the request once it finishes.
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
9 10 11 |
# File 'lib/request_store_rails/middleware.rb', line 9 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
Internal: Assigns a thread-local variable to identify the current store, and cleans up all the variables stored for the request once it finishes.
15 16 17 18 19 20 21 |
# File 'lib/request_store_rails/middleware.rb', line 15 def call(env) RequestLocals.set_current_store_id(extract_request_id(env)) @app.call(env) ensure RequestLocals.clear! RequestLocals.set_current_store_id(nil) end |