Class: Yes::Core::CommandHandling::GuardRunner
- Inherits:
-
Object
- Object
- Yes::Core::CommandHandling::GuardRunner
- Includes:
- OpenTelemetry::Trackable
- Defined in:
- lib/yes/core/command_handling/guard_runner.rb
Overview
Evaluates guards for commands and manages command-specific errors on aggregates Handles the decision of whether to skip guards and properly sets/clears error states
Instance Method Summary collapse
-
#call(cmd, command_name, guard_evaluator_class, skip_guards:) ⇒ GuardEvaluator?
Evaluates guards for the command.
-
#initialize(aggregate) ⇒ GuardRunner
constructor
Initializes a new GuardRunner.
Constructor Details
#initialize(aggregate) ⇒ GuardRunner
Initializes a new GuardRunner
19 20 21 |
# File 'lib/yes/core/command_handling/guard_runner.rb', line 19 def initialize(aggregate) @aggregate = aggregate end |
Instance Method Details
#call(cmd, command_name, guard_evaluator_class, skip_guards:) ⇒ GuardEvaluator?
Evaluates guards for the command
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/yes/core/command_handling/guard_runner.rb', line 33 def call(cmd, command_name, guard_evaluator_class, skip_guards:) if skip_guards clear_command_error(command_name) return nil end evaluator = guard_evaluator_class.new( payload: cmd.payload, metadata: cmd., aggregate: aggregate, command_name: command_name ) evaluator.call clear_command_error(command_name) evaluator rescue GuardEvaluator::InvalidTransition, GuardEvaluator::NoChangeTransition, Yes::Core::Command::Invalid => e aggregate.send(:"#{command_name.to_s.underscore}_error=", e.) raise e end |