class Arkency::CommandBus
Constants
- MultipleHandlers
- UnregisteredHandler
- VERSION
Attributes
handlers[R]
Private Class Methods
new()
click to toggle source
# File lib/arkency/command_bus.rb, line 9 def initialize @handlers = ThreadSafe::Cache.new end
Private Instance Methods
call(command)
click to toggle source
# File lib/arkency/command_bus.rb, line 19 def call(command) handlers .fetch(command.class) { raise UnregisteredHandler.new("Missing handler for #{command.class}") } .(command) end
register(klass, handler)
click to toggle source
# File lib/arkency/command_bus.rb, line 14 def register(klass, handler) raise MultipleHandlers.new("Multiple handlers not allowed for #{klass}") if handlers[klass] handlers[klass] = handler end