Class: Rack::ReplaceableResponse
- Inherits:
-
Object
- Object
- Rack::ReplaceableResponse
- Defined in:
- lib/rack/replaceable_response.rb
Overview
Middleware that allows setting a predefined response for a request. If response is set, it will be returned instead of handing env on to the next middleware/endpoint. Response is stored in env, so it will be eaten by the GC as soon as possible.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ReplaceableResponse
constructor
A new instance of ReplaceableResponse.
- #response_for(env, result = nil) ⇒ Object (also: #set_response_for)
Constructor Details
#initialize(app) ⇒ ReplaceableResponse
Returns a new instance of ReplaceableResponse.
20 |
# File 'lib/rack/replaceable_response.rb', line 20 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
22 |
# File 'lib/rack/replaceable_response.rb', line 22 def call(env) response_for(env) or @app.call(env) end |
#response_for(env, result = nil) ⇒ Object Also known as: set_response_for
21 |
# File 'lib/rack/replaceable_response.rb', line 21 def response_for(env, result = nil) (env['cached.responses'] ||= {})[self] = result end |