Class: Gizmo::Response
- Inherits:
-
Object
- Object
- Gizmo::Response
- Defined in:
- lib/gizmo/models/response.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#data ⇒ Object
Returns the value of attribute data.
-
#format ⇒ Object
Returns the value of attribute format.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #header(name, value) ⇒ Object
-
#initialize(attrs = {}) ⇒ Response
constructor
TODO document options.
- #to_hash(opts = {}) ⇒ Object
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
#callback ⇒ Object
Returns the value of attribute callback.
4 5 6 |
# File 'lib/gizmo/models/response.rb', line 4 def callback @callback end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/gizmo/models/response.rb', line 4 def data @data end |
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'lib/gizmo/models/response.rb', line 4 def format @format end |
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/gizmo/models/response.rb', line 4 def headers @headers end |
#status ⇒ Object
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 |