Class: ApiTransformer::FrontendResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/api_transformer/frontend_response.rb

Overview

Container for frontend response data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFrontendResponse

Returns a new instance of FrontendResponse.



9
10
11
12
13
# File 'lib/api_transformer/frontend_response.rb', line 9

def initialize
  @hash = {}
  @cookies = {}
  @headers = {}
end

Instance Attribute Details

#bodyObject



27
28
29
# File 'lib/api_transformer/frontend_response.rb', line 27

def body
  @hash.any? && @hash.to_json || @body
end

#content_type=(value) ⇒ Object

Sets the attribute content_type

Parameters:

  • value

    the value to set the attribute content_type to.



7
8
9
# File 'lib/api_transformer/frontend_response.rb', line 7

def content_type=(value)
  @content_type = value
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/api_transformer/frontend_response.rb', line 6

def status
  @status
end

Instance Method Details

#headersObject



31
32
33
# File 'lib/api_transformer/frontend_response.rb', line 31

def headers
  [@headers, cookie_header, content_type_header].reduce(&:merge)
end

#set(key, value) ⇒ Object



15
16
17
# File 'lib/api_transformer/frontend_response.rb', line 15

def set(key, value)
  @hash[key] = value
end


19
20
21
# File 'lib/api_transformer/frontend_response.rb', line 19

def set_cookie(key, value)
  @cookies[key] = value
end

#set_header(key, value) ⇒ Object



23
24
25
# File 'lib/api_transformer/frontend_response.rb', line 23

def set_header(key, value)
  @headers[key] = value
end