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, Versioner::Header, Versioner::Param, Versioner::Path
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
- #content_type ⇒ Object
- #content_type_for(format) ⇒ Object
- #content_types ⇒ Object
- #default_options ⇒ Object
-
#initialize(app, options = {}) ⇒ Base
constructor
A new instance of Base.
- #mime_types ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ Base
Returns a new instance of Base.
13 14 15 16 |
# File 'lib/grape/middleware/base.rb', line 13 def initialize(app, = {}) @app = app @options = .merge() end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
9 10 11 |
# File 'lib/grape/middleware/base.rb', line 9 def app @app end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
9 10 11 |
# File 'lib/grape/middleware/base.rb', line 9 def env @env end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/grape/middleware/base.rb', line 9 def @options end |
Instance Method Details
#after ⇒ Response?
This method is abstract.
Called after the application is called in the middleware lifecycle.
39 |
# File 'lib/grape/middleware/base.rb', line 39 def after; end |
#before ⇒ Object
This method is abstract.
Called before the application is called in the middleware lifecycle.
35 |
# File 'lib/grape/middleware/base.rb', line 35 def before; end |
#call(env) ⇒ Object
22 23 24 |
# File 'lib/grape/middleware/base.rb', line 22 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/grape/middleware/base.rb', line 26 def call!(env) @env = env before @app_response = @app.call(@env) after || @app_response end |
#content_type ⇒ Object
57 58 59 |
# File 'lib/grape/middleware/base.rb', line 57 def content_type content_type_for(env['api.format'] || [:format]) || 'text/html' end |
#content_type_for(format) ⇒ Object
49 50 51 |
# File 'lib/grape/middleware/base.rb', line 49 def content_type_for(format) HashWithIndifferentAccess.new(content_types)[format] end |
#content_types ⇒ Object
53 54 55 |
# File 'lib/grape/middleware/base.rb', line 53 def content_types ContentTypes.content_types_for([:content_types]) end |
#default_options ⇒ Object
18 19 20 |
# File 'lib/grape/middleware/base.rb', line 18 def {} end |
#mime_types ⇒ Object
61 62 63 |
# File 'lib/grape/middleware/base.rb', line 61 def mime_types content_types.invert end |
#request ⇒ Object
41 42 43 |
# File 'lib/grape/middleware/base.rb', line 41 def request Rack::Request.new(self.env) end |
#response ⇒ Object
45 46 47 |
# File 'lib/grape/middleware/base.rb', line 45 def response Rack::Response.new(@app_response) end |