Class: Kobako::Payload::Arguments
- Inherits:
-
Data
- Object
- Data
- Kobako::Payload::Arguments
- Defined in:
- lib/kobako/payload/arguments.rb,
sig/kobako/payload/arguments.rbs
Overview
The invocation arguments a Call or a Run carries: a 2-element
msgpack array, args then kwargs. Both elements are always
present, so field positions stay stable when either is empty.
The positional-versus-keyword split lives here rather than in the
core envelope because it is Ruby's call semantics, not the wire's.
SPEC pins kwargs keys to Symbols; the invariant is enforced at
construction so the value object is the single source of truth.
Built on the class X < Data.define(...) subclass form so the class
body is fully Steep-visible; see .rubocop.yml for the
rationale.
Instance Attribute Summary collapse
-
#args ⇒ Array[Kobako::Codec::wire_value]
readonly
Returns the value of attribute args.
-
#kwargs ⇒ Hash[Symbol, Kobako::Codec::wire_value]
readonly
Returns the value of attribute kwargs.
Class Method Summary collapse
-
.decode(bytes) ⇒ Arguments
Decode
bytesinto an Arguments. - .new ⇒ Arguments
Instance Method Summary collapse
- #== ⇒ Boolean
-
#encode ⇒ String
Encode to the
[args, kwargs]msgpack bytes. - #hash ⇒ Integer
-
#initialize(args: [], kwargs: {}) ⇒ Arguments
constructor
A new instance of Arguments.
- #validate_kwargs!(kwargs) ⇒ void
- #with ⇒ Arguments
Constructor Details
#initialize(args: [], kwargs: {}) ⇒ Arguments
Returns a new instance of Arguments.
20 21 22 23 24 25 |
# File 'lib/kobako/payload/arguments.rb', line 20 def initialize(args: [], kwargs: {}) raise ArgumentError, "payload args must be Array" unless args.is_a?(Array) validate_kwargs!(kwargs) super end |
Instance Attribute Details
#args ⇒ Array[Kobako::Codec::wire_value] (readonly)
Returns the value of attribute args.
4 5 6 |
# File 'sig/kobako/payload/arguments.rbs', line 4 def args @args end |
#kwargs ⇒ Hash[Symbol, Kobako::Codec::wire_value] (readonly)
Returns the value of attribute kwargs.
5 6 7 |
# File 'sig/kobako/payload/arguments.rbs', line 5 def kwargs @kwargs end |
Class Method Details
.decode(bytes) ⇒ Arguments
Decode bytes into an Arguments. Raises Codec::InvalidTypeError when
the payload is not the expected 2-element msgpack array, or when the
construction invariants reject the decoded fields.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kobako/payload/arguments.rb', line 36 def self.decode(bytes) Codec::Decoder.decode(bytes) do |frame| unless frame.is_a?(Array) && frame.length == 2 raise Codec::InvalidTypeError, "an invocation payload is malformed (expected a 2-element array)" end args, kwargs = frame new(args: args, kwargs: kwargs) end end |
.new ⇒ Arguments
7 |
# File 'sig/kobako/payload/arguments.rbs', line 7
def self.new: (?args: Array[Kobako::Codec::wire_value], ?kwargs: Hash[Symbol, Kobako::Codec::wire_value]) -> Arguments
|
Instance Method Details
#== ⇒ Boolean
17 |
# File 'sig/kobako/payload/arguments.rbs', line 17
def ==: (untyped other) -> bool
|
#encode ⇒ String
Encode to the [args, kwargs] msgpack bytes. The value object's
own invariants are the contract; this does not re-check the shape.
29 30 31 |
# File 'lib/kobako/payload/arguments.rb', line 29 def encode Codec::Encoder.encode([args, kwargs]) end |
#hash ⇒ Integer
19 |
# File 'sig/kobako/payload/arguments.rbs', line 19
def hash: () -> Integer
|
#validate_kwargs!(kwargs) ⇒ void
This method returns an undefined value.
50 51 52 53 54 55 56 |
# File 'lib/kobako/payload/arguments.rb', line 50 def validate_kwargs!(kwargs) raise ArgumentError, "payload kwargs must be Hash" unless kwargs.is_a?(Hash) kwargs.each_key do |key| raise ArgumentError, "payload kwargs keys must be Symbol, got #{key.class}" unless key.is_a?(Symbol) end end |
#with ⇒ Arguments
15 |
# File 'sig/kobako/payload/arguments.rbs', line 15
def with: (?args: Array[Kobako::Codec::wire_value], ?kwargs: Hash[Symbol, Kobako::Codec::wire_value]) -> Arguments
|