Class: Grape::Middleware::Base
- Inherits:
-
Object
- Object
- Grape::Middleware::Base
- Defined in:
- lib/grape/middleware/base.rb
Direct Known Subclasses
Auth::Basic, Auth::OAuth2, Error, Formatter, Prefixer, Versioner
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 ⇒ Object
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.
8 9 10 11 |
# File 'lib/grape/middleware/base.rb', line 8 def initialize(app, = {}) @app = app @options = .merge() end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
4 5 6 |
# File 'lib/grape/middleware/base.rb', line 4 def app @app end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
4 5 6 |
# File 'lib/grape/middleware/base.rb', line 4 def env @env end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/grape/middleware/base.rb', line 4 def @options end |
Instance Method Details
#after ⇒ Object
This method is abstract.
Called after the application is called in the middleware lifecycle.
32 |
# File 'lib/grape/middleware/base.rb', line 32 def after; end |
#before ⇒ Object
This method is abstract.
Called before the application is called in the middleware lifecycle.
28 |
# File 'lib/grape/middleware/base.rb', line 28 def before; end |
#call(env) ⇒ Object
15 16 17 |
# File 'lib/grape/middleware/base.rb', line 15 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/grape/middleware/base.rb', line 19 def call!(env) @env = env before @app_response = @app.call(@env) after || @app_response end |
#default_options ⇒ Object
13 |
# File 'lib/grape/middleware/base.rb', line 13 def ; {} end |
#request ⇒ Object
34 35 36 |
# File 'lib/grape/middleware/base.rb', line 34 def request Rack::Request.new(self.env) end |
#response ⇒ Object
38 39 40 |
# File 'lib/grape/middleware/base.rb', line 38 def response Rack::Response.new(@app_response) end |