Class: Yoda::Store::Registry::Index
- Inherits:
-
Object
- Object
- Yoda::Store::Registry::Index
- Defined in:
- lib/yoda/store/registry/index.rb
Defined Under Namespace
Classes: ComposerWrapper
Instance Attribute Summary collapse
- #content ⇒ Hash readonly
- #registry_ids ⇒ Set readonly
Instance Method Summary collapse
- #add(address, registry_id) ⇒ Object
- #add_registry(registry) ⇒ Object
-
#get(address, registry_ids: nil) ⇒ IdMask
Return ids of registries which store an object with the address.
-
#initialize(content: {}, registry_ids: Set.new) ⇒ Index
constructor
A new instance of Index.
- #keys ⇒ Object
- #remove(address, registry_id) ⇒ Object
- #remove_registry(registry) ⇒ Object
- #wrap(composer) ⇒ Object
Constructor Details
#initialize(content: {}, registry_ids: Set.new) ⇒ Index
Returns a new instance of Index.
73 74 75 76 |
# File 'lib/yoda/store/registry/index.rb', line 73 def initialize(content: {}, registry_ids: Set.new) @content = content @registry_ids = Set.new(registry_ids) end |
Instance Attribute Details
#content ⇒ Hash (readonly)
68 69 70 |
# File 'lib/yoda/store/registry/index.rb', line 68 def content @content end |
#registry_ids ⇒ Set (readonly)
71 72 73 |
# File 'lib/yoda/store/registry/index.rb', line 71 def registry_ids @registry_ids end |
Instance Method Details
#add(address, registry_id) ⇒ Object
89 90 91 92 93 |
# File 'lib/yoda/store/registry/index.rb', line 89 def add(address, registry_id) content[address.to_sym] ||= Objects::SerializableSet.new content[address.to_sym].add(registry_id.to_sym) content[address.to_sym].select! { |id| registry_ids.member?(id) } end |
#add_registry(registry) ⇒ Object
106 107 108 109 |
# File 'lib/yoda/store/registry/index.rb', line 106 def add_registry(registry) registry_ids.add(registry.id.to_sym) registry.keys.each { |key| add(key, registry.id) } end |
#get(address, registry_ids: nil) ⇒ IdMask
Return ids of registries which store an object with the address.
82 83 84 85 |
# File 'lib/yoda/store/registry/index.rb', line 82 def get(address, registry_ids: nil) raw_content = (content[address.to_sym] ||= Objects::SerializableSet.new) registry_ids ? (IdMask.build(registry_ids) & raw_content) : raw_content end |
#keys ⇒ Object
102 103 104 |
# File 'lib/yoda/store/registry/index.rb', line 102 def keys Set.new(content.keys) end |
#remove(address, registry_id) ⇒ Object
97 98 99 100 |
# File 'lib/yoda/store/registry/index.rb', line 97 def remove(address, registry_id) content[address.to_sym] ||= Objects::SerializableSet.new content[address.to_sym].delete(registry_id.to_sym) end |
#remove_registry(registry) ⇒ Object
111 112 113 |
# File 'lib/yoda/store/registry/index.rb', line 111 def remove_registry(registry) registry_ids.delete(registry.id.to_sym) end |
#wrap(composer) ⇒ Object
115 116 117 |
# File 'lib/yoda/store/registry/index.rb', line 115 def wrap(composer) ComposerWrapper.new(composer: composer, index: self) end |