Class: Yes::Core::Command

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/yes/core/command.rb

Overview

Base command class for all commands in the system. Inherits from Dry::Struct for type-safe attribute definitions.

Defined Under Namespace

Classes: Invalid

Constant Summary collapse

RESERVED_KEYS =
%i[transaction origin batch_id command_id metadata es_encrypted].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(attributes) ⇒ Object

Parameters:

  • attributes (Hash)

    constructor parameters

Raises:

  • (Invalid)

    if the parameters are invalid



21
22
23
24
25
# File 'lib/yes/core/command.rb', line 21

def self.new(attributes)
  super
rescue Dry::Struct::Error => e
  raise Invalid.new(extra: attributes), e
end

Instance Method Details

#payloadHash

Returns the command payload excluding reserved keys.

Returns:

  • (Hash)

    command payload as a hash



30
31
32
# File 'lib/yes/core/command.rb', line 30

def payload
  to_h.except(*RESERVED_KEYS)
end