Class: Yes::Core::Commands::Stateless::GroupHandler
- Inherits:
-
Object
- Object
- Yes::Core::Commands::Stateless::GroupHandler
- Includes:
- HandlerHelpers
- Defined in:
- lib/yes/core/commands/stateless/group_handler.rb
Overview
Handles a group of commands
Defined Under Namespace
Classes: CommandsError, CustomHandlerMethodMissingError, InvalidCommandGroupError
Class Attribute Summary collapse
-
.handlers ⇒ Array<Symbol, Class>
readonly
List of handlers for the command group.
Class Method Summary collapse
-
.handler(command_or_handler_method_name, context: to_s.split('::')[0], subject: to_s.split('::')[1]) ⇒ void
Adds a handler to the command group.
-
.stateless? ⇒ Boolean
Always returns true for stateless handlers.
Instance Method Summary collapse
-
#call ⇒ void
Executes the command group.
-
#initialize(cmd, events_cache: {}) ⇒ GroupHandler
constructor
A new instance of GroupHandler.
Methods included from HandlerHelpers
#activated?, #added?, #deactivated?, #disabled?, #enabled?, #event_exists_with_payload?, #event_in_stream?, #item_added?, #item_assigned?, #item_removed?, #item_unassigned?, #no_change?, #partial_payload_field_changed?, #published?, #removed?, #skip?, #unpublished?
Constructor Details
#initialize(cmd, events_cache: {}) ⇒ GroupHandler
Returns a new instance of GroupHandler.
60 61 62 63 64 65 |
# File 'lib/yes/core/commands/stateless/group_handler.rb', line 60 def initialize(cmd, events_cache: {}) raise InvalidCommandGroupError.new(cmd.class.name.deconstantize, self.class.name.deconstantize) unless valid_command?(cmd) @cmd = cmd @events_cache = events_cache end |
Class Attribute Details
.handlers ⇒ Array<Symbol, Class> (readonly)
Returns List of handlers for the command group.
22 23 24 |
# File 'lib/yes/core/commands/stateless/group_handler.rb', line 22 def handlers @handlers end |
Class Method Details
.handler(command_or_handler_method_name, context: to_s.split('::')[0], subject: to_s.split('::')[1]) ⇒ void
This method returns an undefined value.
Adds a handler to the command group
34 35 36 37 38 |
# File 'lib/yes/core/commands/stateless/group_handler.rb', line 34 def handler(command_or_handler_method_name, context: to_s.split('::')[0], subject: to_s.split('::')[1]) @handlers ||= [] @handlers << build_handler(command_or_handler_method_name, context, subject) end |
.stateless? ⇒ Boolean
Returns Always returns true for stateless handlers.
25 26 27 |
# File 'lib/yes/core/commands/stateless/group_handler.rb', line 25 def stateless? true end |
Instance Method Details
#call ⇒ void
This method returns an undefined value.
Executes the command group
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/yes/core/commands/stateless/group_handler.rb', line 70 def call errors = [] PgEventstore.client.multiple do errors.push(*run_command_handlers) errors.push(*run_custom_handlers) raise CommandsError.new(extra: errors), 'Command group failed' if errors.any? publish_events end end |