Class: Grape::Middleware::Base
- Inherits:
-
Object
- Object
- Grape::Middleware::Base
- Defined in:
- lib/grape/middleware/base.rb
Direct Known Subclasses
Auth::Basic, Auth::Digest, Auth::OAuth2, Error, Filter, Formatter, Prefixer, Versioner::Header, Versioner::Param, Versioner::Path
Defined Under Namespace
Modules: Formats
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#after ⇒ Response?
abstract
Called after the application is called in the middleware lifecycle.
-
#before ⇒ Object
abstract
Called before the application is called in the middleware lifecycle.
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
- #default_options ⇒ Object
-
#initialize(app, options = {}) ⇒ Base
constructor
A new instance of Base.
- #request ⇒ Object
- #response ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ Base
Returns a new instance of Base.
11 12 13 14 |
# File 'lib/grape/middleware/base.rb', line 11 def initialize(app, = {}) @app = app @options = .merge() end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
7 8 9 |
# File 'lib/grape/middleware/base.rb', line 7 def app @app end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/grape/middleware/base.rb', line 7 def env @env end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/grape/middleware/base.rb', line 7 def @options end |
Instance Method Details
#after ⇒ Response?
This method is abstract.
Called after the application is called in the middleware lifecycle.
35 |
# File 'lib/grape/middleware/base.rb', line 35 def after; end |
#before ⇒ Object
This method is abstract.
Called before the application is called in the middleware lifecycle.
31 |
# File 'lib/grape/middleware/base.rb', line 31 def before; end |
#call(env) ⇒ Object
18 19 20 |
# File 'lib/grape/middleware/base.rb', line 18 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/grape/middleware/base.rb', line 22 def call!(env) @env = env before @app_response = @app.call(@env) after || @app_response end |
#default_options ⇒ Object
16 |
# File 'lib/grape/middleware/base.rb', line 16 def ; {} end |
#request ⇒ Object
37 38 39 |
# File 'lib/grape/middleware/base.rb', line 37 def request Rack::Request.new(self.env) end |
#response ⇒ Object
41 42 43 |
# File 'lib/grape/middleware/base.rb', line 41 def response Rack::Response.new(@app_response) end |