Class: Yes::Core::Aggregate::Dsl::CommandDefiner

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

Overview

Factory class that creates and defines commands on aggregates. Handles the creation and registration of all necessary command-related classes, including validation of attributes and DSL evaluation.

Examples:

command_data = CommandData.new(name: :assign_user, aggregate_class: Company)
CommandDefiner.new(command_data).call do
  payload user_id: :uuid

  guard :user_already_assigned do
    user_id.present?
  end

  update_state do
    some_attribute { payload.xyz }
    another_attribute { "#{payload.abc}_#{email}" }
  end
end

Since:

  • 0.1.0

Defined Under Namespace

Classes: DslEvaluator, EventNameResolverError, UndefinedAttributeError

Instance Method Summary collapse

Constructor Details

#initialize(command_data) ⇒ CommandDefiner

Initializes a new CommandDefiner instance

Parameters:

  • command_data (CommandData)

    The data object containing command configuration

Since:

  • 0.1.0



41
42
43
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 41

def initialize(command_data)
  @command_data = command_data
end

Instance Method Details

#call { ... } ⇒ void

This method returns an undefined value.

Generates and registers all necessary classes for the command. This includes command classes, event classes, a guard evaluator class, a state updater class, as well as defining related methods on the aggregate class.

Yields:

  • Block for defining payload, guards and other command configurations

Yield Returns:

  • (void)

Raises:

Since:

  • 0.1.0



53
54
55
56
57
58
59
60
# File 'lib/yes/core/aggregate/dsl/command_definer.rb', line 53

def call(&block)
  create_and_register_block_evaluator_classes
  evaluate_dsl_block(&block) if block
  validate_event_name
  validate_accessed_attributes
  create_and_register_command_classes
  register_command_events
end