Class: Todoplicator::AdapterRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/todoplicator/adapter_registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdapterRegistry

Returns a new instance of AdapterRegistry.



7
8
9
# File 'lib/todoplicator/adapter_registry.rb', line 7

def initialize
  reset!
end

Class Method Details

.instanceObject



3
4
5
# File 'lib/todoplicator/adapter_registry.rb', line 3

def self.instance
  @@instance ||= new
end

Instance Method Details

#add(key, klass) ⇒ Object



11
12
13
# File 'lib/todoplicator/adapter_registry.rb', line 11

def add(key, klass)
  @adapters[key.to_sym] = klass
end

#allObject



19
20
21
# File 'lib/todoplicator/adapter_registry.rb', line 19

def all
  @adapters
end

#for(key) ⇒ Object



15
16
17
# File 'lib/todoplicator/adapter_registry.rb', line 15

def for(key)
  @adapters.fetch(key.to_sym) { raise UnknownAdapter, "#{key} not found" }
end

#reset!Object



23
24
25
# File 'lib/todoplicator/adapter_registry.rb', line 23

def reset!
  @adapters = {}
end