Class: Zodra::ContractRegistry
- Inherits:
-
Object
- Object
- Zodra::ContractRegistry
- Includes:
- Enumerable
- Defined in:
- lib/zodra/contract_registry.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clear! ⇒ Object
- #each ⇒ Object
- #exists?(name) ⇒ Boolean
- #find(name) ⇒ Object
- #find!(name) ⇒ Object
-
#initialize ⇒ ContractRegistry
constructor
A new instance of ContractRegistry.
- #register(name) ⇒ Object
Constructor Details
#initialize ⇒ ContractRegistry
Returns a new instance of ContractRegistry.
11 12 13 |
# File 'lib/zodra/contract_registry.rb', line 11 def initialize @store = {} end |
Class Method Details
.global ⇒ Object
7 8 9 |
# File 'lib/zodra/contract_registry.rb', line 7 def self.global @global ||= new end |
Instance Method Details
#clear! ⇒ Object
38 39 40 |
# File 'lib/zodra/contract_registry.rb', line 38 def clear! @store.clear end |
#each ⇒ Object
34 35 36 |
# File 'lib/zodra/contract_registry.rb', line 34 def each(&) @store.each_value(&) end |
#exists?(name) ⇒ Boolean
30 31 32 |
# File 'lib/zodra/contract_registry.rb', line 30 def exists?(name) @store.key?(name.to_sym) end |
#find(name) ⇒ Object
22 23 24 |
# File 'lib/zodra/contract_registry.rb', line 22 def find(name) @store[name.to_sym] end |
#find!(name) ⇒ Object
26 27 28 |
# File 'lib/zodra/contract_registry.rb', line 26 def find!(name) @store.fetch(name.to_sym) { raise KeyError, "Contract :#{name} is not registered" } end |
#register(name) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/zodra/contract_registry.rb', line 15 def register(name) name = name.to_sym raise DuplicateTypeError, "Contract :#{name} is already registered" if @store.key?(name) @store[name] = Contract.new(name:) end |