Class: Akasha::CommandRouter::DefaultHandler

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(klass) ⇒ 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