Class: Yoda::Store::Registry::Composer
- Inherits:
-
Object
- Object
- Yoda::Store::Registry::Composer
- Defined in:
- lib/yoda/store/registry/composer.rb
Instance Attribute Summary collapse
- #id ⇒ Symbol readonly
- #registries ⇒ Hash{Symbol => Registry} readonly
Instance Method Summary collapse
- #add_registry(registry) ⇒ Object
- #all_registries ⇒ Object
- #get(address, registry_ids: nil) ⇒ Object
- #get_registry(key) ⇒ Object
- #has_registry(key) ⇒ Object
-
#initialize(id:, registries: []) ⇒ Composer
constructor
A new instance of Composer.
- #keys ⇒ Set
- #remove_registry(registry) ⇒ Object
Constructor Details
#initialize(id:, registries: []) ⇒ Composer
Returns a new instance of Composer.
10 11 12 13 |
# File 'lib/yoda/store/registry/composer.rb', line 10 def initialize(id:, registries: []) @id = id @registries = registries.map { |registry| [registry.id.to_sym, registry] }.to_h end |
Instance Attribute Details
#id ⇒ Symbol (readonly)
5 6 7 |
# File 'lib/yoda/store/registry/composer.rb', line 5 def id @id end |
#registries ⇒ Hash{Symbol => Registry} (readonly)
8 9 10 |
# File 'lib/yoda/store/registry/composer.rb', line 8 def registries @registries end |
Instance Method Details
#add_registry(registry) ⇒ Object
15 16 17 |
# File 'lib/yoda/store/registry/composer.rb', line 15 def add_registry(registry) registries[registry.id.to_sym] = registry end |
#all_registries ⇒ Object
44 45 46 |
# File 'lib/yoda/store/registry/composer.rb', line 44 def all_registries registries.values.compact end |
#get(address, registry_ids: nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/yoda/store/registry/composer.rb', line 23 def get(address, registry_ids: nil) registry_mask = IdMask.build(registry_ids) target_registries = registry_mask.any? ? all_registries : registry_mask.covering_ids.map { |id| get_registry(id) }.compact objects_in_registry = target_registries.map { |registry| registry.get(address, registry_ids: registry_mask.nesting_mask(registry.id)) }.compact objects_in_registry.empty? ? nil : Objects::Merger.new(objects_in_registry).merged_instance end |
#get_registry(key) ⇒ Object
36 37 38 |
# File 'lib/yoda/store/registry/composer.rb', line 36 def get_registry(key) registries[key.to_sym] end |
#has_registry(key) ⇒ Object
40 41 42 |
# File 'lib/yoda/store/registry/composer.rb', line 40 def has_registry(key) registries.has_key?(key.to_sym) end |
#keys ⇒ Set
32 33 34 |
# File 'lib/yoda/store/registry/composer.rb', line 32 def keys registries.values.map(&:keys).reduce(Set.new) { |memo, keys| memo + keys } end |
#remove_registry(registry) ⇒ Object
19 20 21 |
# File 'lib/yoda/store/registry/composer.rb', line 19 def remove_registry(registry) registries.delete(registry.id.to_sym) end |