Method: Akasha::CommandRouter#register

Defined in:
lib/akasha/command_router.rb

#register(command, aggregate_class = nil, &block) ⇒ Object

Registers a handler.

As a result, when ‘#route!` is called for that command, the aggregate will be loaded from repository, the command will be sent to the object to invoke the object’s method, and finally the aggregate will be saved.

Raises:

  • (ArgumentError)


18
19
20
21
22
# File 'lib/akasha/command_router.rb', line 18

def register(command, aggregate_class = nil, &block)
  raise ArgumentError, 'Pass either aggregate class or block' if aggregate_class && block
  handler = aggregate_class || block
  @routes[command] = handler
end