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
Constant Summary collapse
- CONTENT_TYPES =
Content types are listed in order of preference.
ActiveSupport::OrderedHash[ :xml, 'application/xml', :serializable_hash, 'application/json', :json, 'application/json', :atom, 'application/atom+xml', :rss, 'application/rss+xml', :txt, 'text/plain', ]
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_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.
22 23 24 25 |
# File 'lib/grape/middleware/base.rb', line 22 def initialize(app, = {}) @app = app @options = .merge() end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
18 19 20 |
# File 'lib/grape/middleware/base.rb', line 18 def app @app end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
18 19 20 |
# File 'lib/grape/middleware/base.rb', line 18 def env @env end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/grape/middleware/base.rb', line 18 def @options end |
Instance Method Details
#after ⇒ Response?
This method is abstract.
Called after the application is called in the middleware lifecycle.
46 |
# File 'lib/grape/middleware/base.rb', line 46 def after; end |
#before ⇒ Object
This method is abstract.
Called before the application is called in the middleware lifecycle.
42 |
# File 'lib/grape/middleware/base.rb', line 42 def before; end |
#call(env) ⇒ Object
29 30 31 |
# File 'lib/grape/middleware/base.rb', line 29 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/grape/middleware/base.rb', line 33 def call!(env) @env = env before @app_response = @app.call(@env) after || @app_response end |
#content_type ⇒ Object
60 61 62 |
# File 'lib/grape/middleware/base.rb', line 60 def content_type content_types[env['api.format'] || [:format]] || 'text/html' end |
#content_types ⇒ Object
56 57 58 |
# File 'lib/grape/middleware/base.rb', line 56 def content_types [:content_types] || CONTENT_TYPES end |
#default_options ⇒ Object
27 |
# File 'lib/grape/middleware/base.rb', line 27 def ; {} end |
#mime_types ⇒ Object
64 65 66 |
# File 'lib/grape/middleware/base.rb', line 64 def mime_types content_types.invert end |
#request ⇒ Object
48 49 50 |
# File 'lib/grape/middleware/base.rb', line 48 def request Rack::Request.new(self.env) end |
#response ⇒ Object
52 53 54 |
# File 'lib/grape/middleware/base.rb', line 52 def response Rack::Response.new(@app_response) end |