Class: CommandProcessor::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/command_processor/processor.rb

Instance Method Summary collapse

Constructor Details

#initializeProcessor

Returns a new instance of Processor.



6
7
8
# File 'lib/command_processor/processor.rb', line 6

def initialize
  @container = Container.new
end

Instance Method Details

#handle(command) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/command_processor/processor.rb', line 14

def handle(command)
  handler_class = Object.const_get("#{command.class.name}Handler")
  handler = @container.resolve_by_type(handler_class)
  handler.handle(command)
rescue ::IOC::UnknownServiceError
  raise(HandlerNotRegisteredError, "Expected handler of type '#{command.class.name}Handler' to be registered")
end

#register(*args, &block) ⇒ Object



10
11
12
# File 'lib/command_processor/processor.rb', line 10

def register(*args, &block)
  @container.register(*args, &block)
end