Class: Newark::Response

Inherits:
Rack::Response
  • Object
show all
Defined in:
lib/newark/response.rb

Constant Summary collapse

JSON_MIME_TYPE =
'application/json'.freeze

Instance Method Summary collapse

Instance Method Details

#body=(value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/newark/response.rb', line 6

def body=(value)
  value = if value.respond_to?(:to_str)
            [ value.to_str ]
          elsif value.respond_to?(:to_hash) && defined?(MultiJson)
            header['Content-Type'] = JSON_MIME_TYPE
            [ MultiJson.dump(value) ]
          elsif value.respond_to?(:to_ary)
            value
          else
            [ value ]
          end

  super value
end