Class: Insika::Command

Inherits:
Data
  • Object
show all
Defined in:
lib/insika/command.rb

Overview

Every mutating interaction becomes a Command. Shared shape:

type:    Symbol (:create_session, :send_message, :trigger_workflow,
               :cancel_task, :resume_task)
payload: Hash validated by the handler
meta:    { command_id:, tenant:, transport:, issued_at: }

Command does not validate payload (that's the handler's job) and does not know about the bus.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#metaObject (readonly)

Returns the value of attribute meta

Returns:

  • (Object)

    the current value of meta



15
16
17
# File 'lib/insika/command.rb', line 15

def meta
  @meta
end

#payloadObject (readonly)

Returns the value of attribute payload

Returns:

  • (Object)

    the current value of payload



15
16
17
# File 'lib/insika/command.rb', line 15

def payload
  @payload
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



15
16
17
# File 'lib/insika/command.rb', line 15

def type
  @type
end

Class Method Details

.build(type, payload = {}, transport: :internal, tenant: nil) ⇒ Object

Factory that fills in the meta defaults. type is normalized to Symbol; a nil payload becomes {} (the handler decides whether required fields are missing).



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/insika/command.rb', line 19

def self.build(type, payload = {}, transport: :internal, tenant: nil)
  new(
    type: type.to_sym,
    payload: payload || {},
    meta: {
      command_id: SecureRandom.uuid,
      tenant: tenant,
      transport: transport,
      issued_at: Time.now.utc.iso8601
    }
  )
end