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

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

Overview

DSL evaluator that backs the ‘command_group :name do … end` block.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_group_data, guard_evaluator_class) ⇒ DslEvaluator

Returns a new instance of DslEvaluator.

Since:

  • 0.1.0



69
70
71
72
# File 'lib/yes/core/aggregate/dsl/command_group_definer.rb', line 69

def initialize(command_group_data, guard_evaluator_class)
  @command_group_data = command_group_data
  @guard_evaluator_class = guard_evaluator_class
end

Instance Attribute Details

#command_group_dataObject (readonly)

Since:

  • 0.1.0



67
68
69
# File 'lib/yes/core/aggregate/dsl/command_group_definer.rb', line 67

def command_group_data
  @command_group_data
end

#guard_evaluator_classObject (readonly)

Since:

  • 0.1.0



67
68
69
# File 'lib/yes/core/aggregate/dsl/command_group_definer.rb', line 67

def guard_evaluator_class
  @guard_evaluator_class
end

Instance Method Details

#command(name) ⇒ void

This method returns an undefined value.

Declare a sub-command. Order is preserved as execution order.

Parameters:

  • name (Symbol)

    the sub-command name (must match a command declared on the same aggregate)

Since:

  • 0.1.0



79
80
81
# File 'lib/yes/core/aggregate/dsl/command_group_definer.rb', line 79

def command(name)
  command_group_data.add_sub_command(name.to_sym)
end

#guard(name, error_extra: {}) { ... } ⇒ void

This method returns an undefined value.

Register a group-level guard. Semantics match the per-command ‘guard` DSL — `:no_change` is recognized as the magic name that raises NoChangeTransition on failure.

Parameters:

  • name (Symbol)

    the guard name

  • error_extra (Hash, Proc) (defaults to: {})

    extra error context

Yields:

  • Block returning true if the guard passes

Since:

  • 0.1.0



91
92
93
94
# File 'lib/yes/core/aggregate/dsl/command_group_definer.rb', line 91

def guard(name, error_extra: {}, &)
  command_group_data.add_guard(name)
  guard_evaluator_class.guard(name, error_extra:, &)
end