Class: Yes::Core::Aggregate::Dsl::CommandData

Inherits:
Object
  • Object
show all
Defined in:
lib/yes/core/aggregate/dsl/command_data.rb

Overview

Data object that holds information about a command definition in an aggregate

Examples:

CommandData.new(:assign_user, UserAggregate, context: 'Users', aggregate: 'User')

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, aggregate_class, options = {}) ⇒ CommandData

Returns a new instance of CommandData.

Parameters:

  • name (Symbol)

    The name of the command

  • aggregate_class (Class)

    The aggregate class this command belongs to

  • options (Hash) (defaults to: {})

    Additional options for the command

Options Hash (options):

  • :context (String)

    The context name for the command

  • :aggregate (String)

    The aggregate name

  • :event_name (String)

    The event name for the command

  • :payload_attributes (Hash)

    The payload attributes for the command

Since:

  • 0.1.0



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 24

def initialize(name, aggregate_class, options = {})
  @name = name
  @aggregate_class = aggregate_class
  @context_name = options.delete(:context)
  @aggregate_name = options.delete(:aggregate)

  # Default event name based on command name (will be overridden if specified in DSL)
  @event_name = options.delete(:event_name) || Yes::Core::Utils::EventNameResolver.call(name)

  # Default payload is just the aggregate_id
  @payload_attributes = options.delete(:payload_attributes) || {}

  # Store guard names
  @guard_names = []

  # Track encrypted attributes for event schema generation
  @encrypted_attributes = []
end

Instance Attribute Details

#aggregate_classObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 13

def aggregate_class
  @aggregate_class
end

#aggregate_nameObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 13

def aggregate_name
  @aggregate_name
end

#authorizer_blockObject

Since:

  • 0.1.0



14
15
16
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 14

def authorizer_block
  @authorizer_block
end

#context_nameObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 13

def context_name
  @context_name
end

#encrypted_attributesObject

Since:

  • 0.1.0



14
15
16
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 14

def encrypted_attributes
  @encrypted_attributes
end

#event_nameObject

Since:

  • 0.1.0



14
15
16
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 14

def event_name
  @event_name
end

#guard_namesObject

Since:

  • 0.1.0



14
15
16
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 14

def guard_names
  @guard_names
end

#nameObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 13

def name
  @name
end

#payload_attributesObject

Since:

  • 0.1.0



14
15
16
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 14

def payload_attributes
  @payload_attributes
end

#update_state_blockObject

Since:

  • 0.1.0



14
15
16
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 14

def update_state_block
  @update_state_block
end

Instance Method Details

#add_guard(name) ⇒ void

This method returns an undefined value.

Add a guard name to the list of guards

Parameters:

  • name (Symbol)

    The name of the guard

Since:

  • 0.1.0



47
48
49
# File 'lib/yes/core/aggregate/dsl/command_data.rb', line 47

def add_guard(name)
  @guard_names << name
end