Class: RailsSimpleEventSourcing::CommandHandlerRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_simple_event_sourcing/command_handler_registry.rb

Defined Under Namespace

Classes: CommandAlreadyRegisteredError

Class Method Summary collapse

Class Method Details

.deregister(command_class) ⇒ Object



18
19
20
# File 'lib/rails_simple_event_sourcing/command_handler_registry.rb', line 18

def self.deregister(command_class)
  @registry.delete(command_class)
end

.handler_for(command_class) ⇒ Object



22
23
24
# File 'lib/rails_simple_event_sourcing/command_handler_registry.rb', line 22

def self.handler_for(command_class)
  @registry[command_class]
end

.register(command_class, handler_class) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rails_simple_event_sourcing/command_handler_registry.rb', line 10

def self.register(command_class, handler_class)
  if @registry.key?(command_class)
    raise CommandAlreadyRegisteredError, "Command handler already registered for #{command_class}"
  end

  @registry[command_class] = handler_class
end