Class: Grape::Middleware::Base
- Inherits:
-
Object
- Object
- Grape::Middleware::Base
- Defined in:
- lib/grape/middleware/base.rb
Direct Known Subclasses
Auth::Base, Auth::OAuth2, Error, Filter, Formatter, Globals, Versioner::AcceptVersionHeader, 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
- #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 ⇒ Response?
This method is abstract.
Called after the application is called in the middleware lifecycle.
36 37 |
# File 'lib/grape/middleware/base.rb', line 36 def after end |
#before ⇒ Object
This method is abstract.
Called before the application is called in the middleware lifecycle.
30 31 |
# File 'lib/grape/middleware/base.rb', line 30 def before end |
#call(env) ⇒ Object
17 18 19 |
# File 'lib/grape/middleware/base.rb', line 17 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/grape/middleware/base.rb', line 21 def call!(env) @env = env before @app_response = @app.call(@env) after || @app_response end |
#content_type ⇒ Object
51 52 53 |
# File 'lib/grape/middleware/base.rb', line 51 def content_type content_type_for(env['api.format'] || [:format]) || 'text/html' end |
#content_type_for(format) ⇒ Object
43 44 45 |
# File 'lib/grape/middleware/base.rb', line 43 def content_type_for(format) HashWithIndifferentAccess.new(content_types)[format] end |
#content_types ⇒ Object
47 48 49 |
# File 'lib/grape/middleware/base.rb', line 47 def content_types ContentTypes.content_types_for([:content_types]) end |
#default_options ⇒ Object
13 14 15 |
# File 'lib/grape/middleware/base.rb', line 13 def {} end |
#mime_types ⇒ Object
55 56 57 58 59 |
# File 'lib/grape/middleware/base.rb', line 55 def mime_types content_types.each_with_object({}) { |(k, v), types_without_params| types_without_params[k] = v.split(';').first }.invert end |
#response ⇒ Object
39 40 41 |
# File 'lib/grape/middleware/base.rb', line 39 def response Rack::Response.new(@app_response) end |