Class: Kobako::Wire::Envelope::Response
- Inherits:
-
Data
- Object
- Data
- Kobako::Wire::Envelope::Response
- Defined in:
- lib/kobako/wire/envelope.rb
Overview
Response (SPEC.md Wire Codec → Response)
2-element msgpack array: [status, value-or-error]. status is 0 (success) or 1 (error). For success the second element is the return value; for error it is an Kobako::Wire::Exception (ext 0x02 envelope).
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #err? ⇒ Boolean
-
#initialize(status:, payload:) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
Constructor Details
#initialize(status:, payload:) ⇒ Response
Returns a new instance of Response.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/kobako/wire/envelope.rb', line 115 def initialize(status:, payload:) unless [STATUS_OK, STATUS_ERROR].include?(status) raise ArgumentError, "Response status must be 0 or 1, got #{status.inspect}" end if status == STATUS_ERROR && !payload.is_a?(Exception) raise ArgumentError, "Response status=1 payload must be Kobako::Wire::Exception" end super end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload
102 103 104 |
# File 'lib/kobako/wire/envelope.rb', line 102 def payload @payload end |
#status ⇒ Object (readonly)
Returns the value of attribute status
102 103 104 |
# File 'lib/kobako/wire/envelope.rb', line 102 def status @status end |
Class Method Details
.err(exception) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/kobako/wire/envelope.rb', line 107 def self.err(exception) unless exception.is_a?(Exception) raise ArgumentError, "Response.err requires Kobako::Wire::Exception, got #{exception.class}" end new(status: STATUS_ERROR, payload: exception) end |
.ok(value) ⇒ Object
103 104 105 |
# File 'lib/kobako/wire/envelope.rb', line 103 def self.ok(value) new(status: STATUS_OK, payload: value) end |
Instance Method Details
#err? ⇒ Boolean
127 |
# File 'lib/kobako/wire/envelope.rb', line 127 def err? = status == STATUS_ERROR |