Class: Webmate::Responders::Response
- Inherits:
-
Object
- Object
- Webmate::Responders::Response
- Defined in:
- lib/webmate/responders/response.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#data ⇒ Object
Returns the value of attribute data.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(data, options = {}) ⇒ Response
constructor
A new instance of Response.
- #json ⇒ Object
- #packed ⇒ Object
- #rack_format ⇒ Object
- #safe_params ⇒ Object
Constructor Details
#initialize(data, options = {}) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 |
# File 'lib/webmate/responders/response.rb', line 5 def initialize(data, = {}) @data = data @status = [:status] || 200 @params = [:params] || {} @action = [:action] || @params[:action] || '' = [:metadata] || {} @path = [:path] || "/" end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/webmate/responders/response.rb', line 4 def action @action end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/webmate/responders/response.rb', line 4 def data @data end |
#metadata ⇒ Object
Returns the value of attribute metadata.
4 5 6 |
# File 'lib/webmate/responders/response.rb', line 4 def end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/webmate/responders/response.rb', line 4 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/webmate/responders/response.rb', line 4 def path @path end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/webmate/responders/response.rb', line 4 def status @status end |
Instance Method Details
#json ⇒ Object
14 15 16 |
# File 'lib/webmate/responders/response.rb', line 14 def json Yajl::Encoder.new.encode(self.packed) end |
#packed ⇒ Object
18 19 20 |
# File 'lib/webmate/responders/response.rb', line 18 def packed { action: @action, resource: @resource, response: @data, params: safe_params } end |
#rack_format ⇒ Object
32 33 34 |
# File 'lib/webmate/responders/response.rb', line 32 def rack_format [@status, {}, @data] end |
#safe_params ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/webmate/responders/response.rb', line 22 def safe_params safe_params = {} params.each do |key, value| if value.is_a?(String) || value.is_a?(Integer) safe_params[key] = value end end safe_params end |