Class: Yes::Core::Aggregate::Dsl::MethodDefiners::CommandGroup::CanCommandGroup
- Inherits:
-
Base
- Object
- Base
- Yes::Core::Aggregate::Dsl::MethodDefiners::CommandGroup::CanCommandGroup
- Defined in:
- lib/yes/core/aggregate/dsl/method_definers/command_group/can_command_group.rb
Overview
Defines ‘aggregate.can_<group_name>?(payload = {})` and the `<group_name>_error` accessor on the aggregate class.
Mirrors Yes::Core::Aggregate::Dsl::MethodDefiners::Command::CanCommand but resolves the group’s GuardEvaluator class instead of a command’s.
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Yes::Core::Aggregate::Dsl::MethodDefiners::CommandGroup::Base
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yes/core/aggregate/dsl/method_definers/command_group/can_command_group.rb', line 15 def call can_method = :"can_#{@name}?" error_method = :"#{@name}_error" aggregate_class.attr_accessor error_method group_name = @name aggregate_class.define_method(can_method) do |payload = {}| cmd = command_utilities.build_group_command(group_name, payload) guard_evaluator_class = command_utilities.fetch_guard_evaluator_class_for_group(group_name) Yes::Core::CommandHandling::GuardRunner.new(self).call( cmd, group_name, guard_evaluator_class, skip_guards: false ).present? rescue Yes::Core::CommandHandling::GuardEvaluator::InvalidTransition, Yes::Core::CommandHandling::GuardEvaluator::NoChangeTransition, Yes::Core::Command::Invalid false end end |