Class: Goliath::Rack::DefaultResponseFormat

Inherits:
Object
  • Object
show all
Includes:
AsyncMiddleware
Defined in:
lib/goliath/rack/default_response_format.rb

Instance Method Summary collapse

Methods included from AsyncMiddleware

#call, #final_response?, #hook_into_callback_chain, #initialize

Methods included from Validator

safely, validation_error

Instance Method Details

#post_process(env, status, headers, body) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/goliath/rack/default_response_format.rb', line 6

def post_process(env, status, headers, body)
  return [status, headers, body] if body.respond_to?(:to_ary)

  new_body = []
  if body.respond_to?(:each)
    body.each { |chunk| new_body << chunk }
  else
    new_body << body
  end
  new_body.collect! { |item| item.to_s }

  [status, headers, new_body.flatten]
end