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.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, options = {}) ⇒ Response
constructor
A new instance of Response.
- #to_packet ⇒ Object
- #to_rack ⇒ 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 |
Class Method Details
.build_error(message, options = {}) ⇒ Object
27 28 29 |
# File 'lib/webmate/responders/response.rb', line 27 def build_error(, = {}) self.new(, {status: 500}.merge()) end |
.build_not_found(message, options = {}) ⇒ Object
23 24 25 |
# File 'lib/webmate/responders/response.rb', line 23 def build_not_found(, = {}) self.new(, {status: 404}.merge()) end |
Instance Method Details
#to_packet ⇒ Object
18 19 20 |
# File 'lib/webmate/responders/response.rb', line 18 def to_packet Webmate::SocketIO::Packets::Message.build_response_packet(self).to_packet end |
#to_rack ⇒ Object
14 15 16 |
# File 'lib/webmate/responders/response.rb', line 14 def to_rack [@status, {}, @data] end |