Class: Commandos::IAmACommandRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/commandos/registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(storage: DefaultStorageStrategy) ⇒ IAmACommandRegistry

Returns a new instance of IAmACommandRegistry.



3
4
5
# File 'lib/commandos/registry.rb', line 3

def initialize(storage: DefaultStorageStrategy)
  @storage = storage
end

Instance Method Details

#[](command) ⇒ Object Also known as: find_by



7
8
9
10
11
# File 'lib/commandos/registry.rb', line 7

def [](command)
  handlers.fetch(storage_strategy.call command) { NullHandler }.tap do |handler|
    yield handler if block_given?
  end
end