Class: Grape::Middleware::Base
- Inherits:
-
Object
- Object
- Grape::Middleware::Base
show all
- Defined in:
- lib/grape/middleware/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(app, options = {}) ⇒ Base
8
9
10
11
|
# File 'lib/grape/middleware/base.rb', line 8
def initialize(app, options = {})
@app = app
@options = default_options.merge(options)
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
4
5
6
|
# File 'lib/grape/middleware/base.rb', line 4
def app
@app
end
|
#env ⇒ Object
Returns the value of attribute env.
4
5
6
|
# File 'lib/grape/middleware/base.rb', line 4
def env
@env
end
|
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'lib/grape/middleware/base.rb', line 4
def options
@options
end
|
Instance Method Details
#after ⇒ Response?
Called after the application is called in the middleware lifecycle.
34
|
# File 'lib/grape/middleware/base.rb', line 34
def after; end
|
#before ⇒ Object
Called before the application is called in the middleware lifecycle.
30
|
# 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
52
53
54
|
# File 'lib/grape/middleware/base.rb', line 52
def content_type
content_type_for(env['api.format'] || options[:format]) || 'text/html'
end
|
#content_type_for(format) ⇒ Object
44
45
46
|
# File 'lib/grape/middleware/base.rb', line 44
def content_type_for(format)
HashWithIndifferentAccess.new(content_types)[format]
end
|
#content_types ⇒ Object
48
49
50
|
# File 'lib/grape/middleware/base.rb', line 48
def content_types
ContentTypes.content_types_for(options[:content_types])
end
|
#default_options ⇒ Object
13
14
15
|
# File 'lib/grape/middleware/base.rb', line 13
def default_options
{}
end
|
#mime_types ⇒ Object
56
57
58
|
# File 'lib/grape/middleware/base.rb', line 56
def mime_types
content_types.invert
end
|
#request ⇒ Object
36
37
38
|
# File 'lib/grape/middleware/base.rb', line 36
def request
Grape::Request.new(env)
end
|
#response ⇒ Object
40
41
42
|
# File 'lib/grape/middleware/base.rb', line 40
def response
Rack::Response.new(@app_response)
end
|