Class: Kobako::RPC::Response
- Inherits:
-
Data
- Object
- Data
- Kobako::RPC::Response
- Defined in:
- lib/kobako/rpc/envelope.rb
Overview
Value object for a single host-side RPC Response (SPEC.md Wire Codec → Response).
2-element msgpack array: [status, value-or-fault]. status is 0 (success) or 1 (fault). For success the second element is the return value; for fault it is a Fault (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
- .error(fault) ⇒ Object
-
.ok(value) ⇒ Object
steep:ignore:start.
Instance Method Summary collapse
- #error? ⇒ 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.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/kobako/rpc/envelope.rb', line 88 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?(Kobako::RPC::Fault) raise ArgumentError, "Response status=1 payload must be Kobako::RPC::Fault" end super end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload
74 75 76 |
# File 'lib/kobako/rpc/envelope.rb', line 74 def payload @payload end |
#status ⇒ Object (readonly)
Returns the value of attribute status
74 75 76 |
# File 'lib/kobako/rpc/envelope.rb', line 74 def status @status end |
Class Method Details
.error(fault) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/kobako/rpc/envelope.rb', line 80 def self.error(fault) unless fault.is_a?(Kobako::RPC::Fault) raise ArgumentError, "Response.error requires Kobako::RPC::Fault, got #{fault.class}" end new(status: STATUS_ERROR, payload: fault) end |
.ok(value) ⇒ Object
steep:ignore:start
76 77 78 |
# File 'lib/kobako/rpc/envelope.rb', line 76 def self.ok(value) new(status: STATUS_OK, payload: value) end |
Instance Method Details
#error? ⇒ Boolean
100 101 |
# File 'lib/kobako/rpc/envelope.rb', line 100 def error? = status == STATUS_ERROR # steep:ignore:end |