class ApiTransformer::FrontendResponse
Container for frontend response data
Attributes
body[W]
content_type[W]
status[RW]
Public Class Methods
new()
click to toggle source
# File lib/api_transformer/frontend_response.rb, line 9 def initialize @hash = {} @cookies = {} @headers = {} end
Public Instance Methods
body()
click to toggle source
# File lib/api_transformer/frontend_response.rb, line 27 def body @hash.any? && @hash.to_json || @body end
headers()
click to toggle source
# File lib/api_transformer/frontend_response.rb, line 31 def headers [@headers, cookie_header, content_type_header].reduce(&:merge) end
set(key, value)
click to toggle source
# File lib/api_transformer/frontend_response.rb, line 15 def set(key, value) @hash[key] = value end
set_header(key, value)
click to toggle source
# File lib/api_transformer/frontend_response.rb, line 23 def set_header(key, value) @headers[key] = value end
Private Instance Methods
content_type()
click to toggle source
# File lib/api_transformer/frontend_response.rb, line 50 def content_type if @content_type @content_type elsif @hash "application/json" else "text/plain" end end
content_type_header()
click to toggle source
# File lib/api_transformer/frontend_response.rb, line 46 def content_type_header { "Content-Type" => content_type } end