Class: Akasha::CommandRouter::DefaultHandler
- Inherits:
-
Object
- Object
- Akasha::CommandRouter::DefaultHandler
- Defined in:
- lib/akasha/command_router/default_handler.rb
Overview
Default command handler. Works by loading aggregate from the repo by id, invoking its method ‘command`, passing all data, and saving changes to the aggregate in the end.
Instance Method Summary collapse
- #call(command, aggregate_id, **data) ⇒ Object
-
#initialize(klass) ⇒ DefaultHandler
constructor
A new instance of DefaultHandler.
Constructor Details
#initialize(klass) ⇒ DefaultHandler
Returns a new instance of DefaultHandler.
8 9 10 |
# File 'lib/akasha/command_router/default_handler.rb', line 8 def initialize(klass) @klass = klass end |
Instance Method Details
#call(command, aggregate_id, **data) ⇒ Object
12 13 14 15 16 |
# File 'lib/akasha/command_router/default_handler.rb', line 12 def call(command, aggregate_id, **data) aggregate = @klass.find_or_create(aggregate_id) aggregate.public_send(command, **data) aggregate.save! end |