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)
-
- (Object) app
readonly
Returns the value of attribute app.
-
- (Object) env
readonly
Returns the value of attribute env.
-
- (Object) options
readonly
Returns the value of attribute options.
Instance Method Summary (collapse)
-
- (Response?) after
abstract
Called after the application is called in the middleware lifecycle.
-
- (Object) before
abstract
Called before the application is called in the middleware lifecycle.
- - (Object) call(env)
- - (Object) call!(env)
- - (Object) content_type
- - (Object) content_type_for(format)
- - (Object) content_types
- - (Object) default_options
-
- (Base) initialize(app, options = {})
constructor
A new instance of Base.
- - (Object) mime_types
- - (Object) request
- - (Object) response
Constructor Details
- (Base) initialize(app, options = {})
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
- (Object) app (readonly)
Returns the value of attribute app
4 5 6 |
# File 'lib/grape/middleware/base.rb', line 4 def app @app end |
- (Object) env (readonly)
Returns the value of attribute env
4 5 6 |
# File 'lib/grape/middleware/base.rb', line 4 def env @env end |
- (Object) options (readonly)
Returns the value of attribute options
4 5 6 |
# File 'lib/grape/middleware/base.rb', line 4 def @options end |
Instance Method Details
- (Response?) after
This method is abstract.
Called after the application is called in the middleware lifecycle.
34 |
# File 'lib/grape/middleware/base.rb', line 34 def after; end |
- (Object) before
This method is abstract.
Called before the application is called in the middleware lifecycle.
30 |
# File 'lib/grape/middleware/base.rb', line 30 def before; end |
- (Object) call(env)
17 18 19 |
# File 'lib/grape/middleware/base.rb', line 17 def call(env) dup.call!(env) end |
- (Object) call!(env)
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 |
- (Object) content_type
52 53 54 |
# File 'lib/grape/middleware/base.rb', line 52 def content_type content_type_for(env['api.format'] || [:format]) || 'text/html' end |
- (Object) content_type_for(format)
44 45 46 |
# File 'lib/grape/middleware/base.rb', line 44 def content_type_for(format) HashWithIndifferentAccess.new(content_types)[format] end |
- (Object) content_types
48 49 50 |
# File 'lib/grape/middleware/base.rb', line 48 def content_types ContentTypes.content_types_for([:content_types]) end |
- (Object) default_options
13 14 15 |
# File 'lib/grape/middleware/base.rb', line 13 def {} end |
- (Object) mime_types
56 57 58 |
# File 'lib/grape/middleware/base.rb', line 56 def mime_types content_types.invert end |
- (Object) request
36 37 38 |
# File 'lib/grape/middleware/base.rb', line 36 def request Rack::Request.new(self.env) end |
- (Object) response
40 41 42 |
# File 'lib/grape/middleware/base.rb', line 40 def response Rack::Response.new(@app_response) end |