Class: Grape::Middleware::Formatter
- Inherits:
-
Base
- Object
- Base
- Grape::Middleware::Formatter
show all
- Defined in:
- lib/grape/middleware/formatter.rb
Instance Attribute Summary
Attributes inherited from Base
#app, #env, #options
Instance Method Summary
collapse
Methods inherited from Base
#call, #call!, #content_type, #content_type_for, #content_types, #initialize, #mime_types, #request, #response
Instance Method Details
#after ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/grape/middleware/formatter.rb', line 24
def after
status, , bodies = *@app_response
formatter = Grape::Formatter::Base.formatter_for env['api.format'], options
bodymap = bodies.collect do |body|
formatter.call body, env
end
['Content-Type'] = content_type_for(env['api.format']) unless ['Content-Type']
Rack::Response.new(bodymap, status, ).to_a
end
|
#before ⇒ Object
19
20
21
22
|
# File 'lib/grape/middleware/formatter.rb', line 19
def before
negotiate_content_type
read_body_input
end
|
#default_options ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/grape/middleware/formatter.rb', line 7
def default_options
{
:default_format => :txt,
:formatters => {},
:parsers => {}
}
end
|
15
16
17
|
# File 'lib/grape/middleware/formatter.rb', line 15
def
env.dup.inject({}){|h,(k,v)| h[k.to_s.downcase[5..-1]] = v if k.to_s.downcase.start_with?('http_'); h}
end
|