Class: Yes::Core::Aggregate::Dsl::MethodDefiners::CommandGroup::CommandGroup

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

Overview

Defines ‘aggregate.<group_name>(payload = nil, **options)` on the aggregate class. Mirrors Yes::Core::Aggregate::Dsl::MethodDefiners::Command::Command but delegates to CommandHandling::CommandGroupHandler.

Since:

  • 0.1.0

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Yes::Core::Aggregate::Dsl::MethodDefiners::CommandGroup::Base

Instance Method Details

#callObject

Since:

  • 0.1.0



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yes/core/aggregate/dsl/method_definers/command_group/command_group.rb', line 13

def call
  group_name = @name

  aggregate_class.define_method(group_name) do |payload = nil, **options|
    payload = payload.clone if payload.is_a?(Hash)

    guards = options.delete(:guards)
    guards = true if guards.nil?
     = options.delete(:metadata)

    if payload.nil? && !options.empty?
      payload = options
    elsif payload.nil?
      payload = {}
    end

    Yes::Core::CommandHandling::CommandGroupHandler.new(self).call(
      group_name, payload, guards:, metadata:
    )
  end
end