Class/Module Index [+]

Quicksearch

Grape::Middleware::Formatter

Public Instance Methods

after() click to toggle source
# File lib/grape/middleware/formatter.rb, line 26
def after
  status, headers, bodies = *@app_response
  # allow content-type to be explicitly overwritten
  api_format = mime_types[headers["Content-Type"]] || env['api.format']
  formatter = Grape::Formatter::Base.formatter_for api_format, options
  begin
    bodymap = bodies.collect do |body|
      formatter.call body, env
    end
  rescue Grape::Exceptions::InvalidFormatter => e
    throw :error, status: 500, message: e.message
  end
  headers['Content-Type'] = content_type_for(env['api.format']) unless headers['Content-Type']
  Rack::Response.new(bodymap, status, headers).to_a
end
before() click to toggle source
# File lib/grape/middleware/formatter.rb, line 21
def before
  negotiate_content_type
  read_body_input
end
default_options() click to toggle source
# File lib/grape/middleware/formatter.rb, line 6
def default_options
  {
    default_format: :txt,
    formatters: {},
    parsers: {}
  }
end
headers() click to toggle source
# File lib/grape/middleware/formatter.rb, line 14
def headers
  env.dup.inject({}) do |h, (k, v)|
    h[k.to_s.downcase[5..-1]] = v if k.to_s.downcase.start_with?('http_')
    h
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.