Module: Foobara::CommandPatternImplementation
- Includes:
- CommandPatternImplementation::Concerns::Callbacks, CommandPatternImplementation::Concerns::CommandData, CommandPatternImplementation::Concerns::DomainMappers, CommandPatternImplementation::Concerns::Errors, CommandPatternImplementation::Concerns::ErrorsType, CommandPatternImplementation::Concerns::Inputs, CommandPatternImplementation::Concerns::InputsType, CommandPatternImplementation::Concerns::Namespace, CommandPatternImplementation::Concerns::Reflection, CommandPatternImplementation::Concerns::Result, CommandPatternImplementation::Concerns::ResultType, CommandPatternImplementation::Concerns::Runtime, CommandPatternImplementation::Concerns::StateMachine, CommandPatternImplementation::Concerns::Subcommands, Concern, TruncatedInspect
- Included in:
- Command, DomainMapper
- Defined in:
- foobara-0.7.3/projects/command/src/command_pattern_implementation.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/errors.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/inputs.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/result.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/runtime.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/callbacks.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/namespace.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/reflection.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/errors_type.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/inputs_type.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/result_type.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/subcommands.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/command_data.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/state_machine.rb,
foobara-0.7.3/projects/command/src/command_pattern_implementation/concerns/domain_mappers.rb,
foobara-0.7.3/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/runtime.rb,
foobara-0.7.3/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entities.rb,
foobara-0.7.3/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/transactions.rb,
foobara-0.7.3/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entity_inputs.rb,
foobara-0.7.3/projects/model_plumbing/src/extensions/command_pattern_implementation/concerns/model_inputs_type.rb,
foobara-0.7.3/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entity_reflection.rb,
foobara-0.7.3/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/entity_errors_type.rb,
foobara-0.7.3/projects/entities_plumbing/src/extensions/command_pattern_implementation/concerns/transactional_runtime.rb
Overview
We distinguish between "Foobara Command" and the "command pattern".
A "Foobara Command" encapsulates a high-level business operation and serves as the public interface to its domain.
The "command pattern" encapsulates an operation behind an interface that supports .new(inputs), #run which returns an outcome which implements #success?, #result, and #errors.
All "Foobara Command"s implement the "command pattern" but not all implementations of the "command pattern" are "Foobara Command"s. An example is DomainMappers. They happen to use the "command pattern" since it is a good fit but has nothing to do with a public interface high-level business operation encapsulation like a "Foobara Command" does.
Defined Under Namespace
Modules: Concerns Classes: BadCommandInputsError
Constant Summary
Constants included from TruncatedInspect
Class Method Summary collapse
Methods included from TruncatedInspect
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Class Method Details
.install_state_machine_callback_methods ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'projects/command/src/command_pattern_implementation/concerns/callbacks.rb', line 39 def install_state_machine_callback_methods [self, ClassMethods].each do |target| [:before, :after].each do |type| target.define_method "#{type}_any_transition" do |&block| state_machine_callback_registry.register_callback(type) do |state_machine:, **args| block.call(command: state_machine.owner, **args) end end end target.define_method "around_any_transition" do |&block| state_machine_callback_registry.register_callback( :around ) do |state_machine:, **args, &do_transition_block| block.call(command: state_machine.owner, **args, &do_transition_block) end end target.define_method :error_any_transition do |&block| state_machine_callback_registry.register_callback(:error) do |error| callback_data = error.callback_data state_machine = callback_data[:state_machine] command = state_machine.owner from = callback_data[:from] transition = callback_data[:transition] to = callback_data[:to] block.call(error:, command:, state_machine:, from:, to:, transition:) end end end Foobara::Command::StateMachine.transitions.each do |transition| [self, ClassMethods].each do |target| [:before, :after].each do |type| target.define_method "#{type}_#{transition}" do |&block| state_machine_callback_registry.register_callback( type, transition: ) do |state_machine:, **args| block.call(command: state_machine.owner, **args) end end end target.define_method "around_#{transition}" do |&block| state_machine_callback_registry.register_callback( :around, transition: ) do |state_machine:, **args, &do_transition_block| block.call(command: state_machine.owner, **args, &do_transition_block) end end end end end |