Class: Gizmo::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/gizmo/models/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Response

TODO document options



7
8
9
10
11
12
13
14
# File 'lib/gizmo/models/response.rb', line 7

def initialize(attrs={})
  @headers = {}

  attrs.each do |name, val|
    setter = :"#{name}="
    send(setter, val) if respond_to? setter
  end
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



4
5
6
# File 'lib/gizmo/models/response.rb', line 4

def callback
  @callback
end

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/gizmo/models/response.rb', line 4

def data
  @data
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/gizmo/models/response.rb', line 4

def format
  @format
end

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/gizmo/models/response.rb', line 4

def headers
  @headers
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/gizmo/models/response.rb', line 4

def status
  @status
end

Instance Method Details

#header(name, value) ⇒ Object



16
17
18
# File 'lib/gizmo/models/response.rb', line 16

def header(name, value)
  headers[name.to_s] = value.to_s
end

#to_hash(opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/gizmo/models/response.rb', line 20

def to_hash(opts={})
  hash = {
    format => data.as_json(opts),
    status: status,
    callback: callback
  }
  hash[:headers] = headers unless headers.nil? || headers.empty?
  hash
end