Class: Yes::Core::Aggregate::Dsl::CommandGroupDefiner

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

Overview

Factory class that creates and defines command_groups on aggregates.

Mirrors CommandDefiner. The DSL evaluator inside accepts two methods: ‘command :sub_command_name` to push a sub-command symbol, and `guard(name, error_extra: …) { … }` to register a group-level guard on the generated GuardEvaluator class.

Examples:

group_data = CommandGroupData.new(:create_apprenticeship, MyAggregate,
                                  context: 'Companies', aggregate: 'Apprenticeship')
CommandGroupDefiner.new(group_data).call do
  command :assign_company
  command :change_name

  guard(:company_assigned) { company_id.present? }
end

Since:

  • 0.1.0

Defined Under Namespace

Classes: DslEvaluator, UnknownSubCommandError

Instance Method Summary collapse

Constructor Details

#initialize(command_group_data) ⇒ CommandGroupDefiner

Returns a new instance of CommandGroupDefiner.

Parameters:

Since:

  • 0.1.0



31
32
33
# File 'lib/yes/core/aggregate/dsl/command_group_definer.rb', line 31

def initialize(command_group_data)
  @command_group_data = command_group_data
end

Instance Method Details

#call { ... } ⇒ void

This method returns an undefined value.

Generates and registers all classes/methods for the command group.

Yields:

  • Block for declaring sub-commands and guards

Since:

  • 0.1.0



39
40
41
42
43
44
# File 'lib/yes/core/aggregate/dsl/command_group_definer.rb', line 39

def call(&block)
  create_and_register_guard_evaluator
  evaluate_dsl_block(&block) if block
  create_and_register_command
  define_aggregate_methods
end