Class: InventoryRefresh::InventoryCollection::ReferencesStorage
- Inherits:
-
Object
- Object
- InventoryRefresh::InventoryCollection::ReferencesStorage
- Defined in:
- lib/inventory_refresh/inventory_collection/references_storage.rb
Instance Attribute Summary collapse
-
#attribute_references ⇒ Set
readonly
A set of InventoryObject attributes names, which tells us InventoryObject attributes were referenced by other InventoryObject objects using a lazy_find with :key.
-
#references ⇒ Hash
readonly
A set of InventoryObjects manager_uuids, which tells us which InventoryObjects were referenced by other InventoryObjects using a lazy_find.
Instance Method Summary collapse
-
#<<(reference_data) ⇒ Object
Adds reference to the storage.
-
#add_reference(reference_data, key: nil, ref: nil) ⇒ Object
Adds reference to the storage.
-
#build_reference(reference_data, ref = nil) ⇒ Object
Builds a Reference object.
-
#build_stringified_reference(hash, keys) ⇒ String
Builds string uuid from passed Hash and keys.
-
#build_stringified_reference_for_record(record, keys) ⇒ String
Builds string uuid from passed Object and keys.
-
#initialize(index_proxy) ⇒ ReferencesStorage
constructor
A new instance of ReferencesStorage.
-
#merge!(references_array, ref: nil) ⇒ InventoryRefresh::InventoryCollection::ReferencesStorage
Adds array of references to the storage.
-
#primary_references ⇒ Hash{String => InventoryRefresh::InventoryCollection::Reference}
Hash of indexed Reference objects.
Constructor Details
#initialize(index_proxy) ⇒ ReferencesStorage
Returns a new instance of ReferencesStorage.
12 13 14 15 16 17 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 12 def initialize(index_proxy) @index_proxy = index_proxy @references = {} @references[primary_index_ref] = {} @attribute_references = Set.new end |
Instance Attribute Details
#attribute_references ⇒ Set (readonly)
Returns A set of InventoryObject attributes names, which tells us InventoryObject attributes were referenced by other InventoryObject objects using a lazy_find with :key.
10 11 12 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 10 def attribute_references @attribute_references end |
#references ⇒ Hash (readonly)
Returns A set of InventoryObjects manager_uuids, which tells us which InventoryObjects were referenced by other InventoryObjects using a lazy_find.
6 7 8 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 6 def references @references end |
Instance Method Details
#<<(reference_data) ⇒ Object
Adds reference to the storage. The reference can be already existing, otherwise we attempt to build it. This is simplified version of add_reference, not allowing to define :key or :ref.
44 45 46 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 44 def <<(reference_data) add_reference(reference_data) end |
#add_reference(reference_data, key: nil, ref: nil) ⇒ Object
Adds reference to the storage. The reference can be already existing, otherwise we attempt to build it.
28 29 30 31 32 33 34 35 36 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 28 def add_reference(reference_data, key: nil, ref: nil) reference = build_reference(reference_data, ref) specific_references = references[reference.ref] ||= {} specific_references[reference.stringified_reference] = reference # If we access an attribute of the value, using a :key, we want to keep a track of that attribute_references << key if key end |
#build_reference(reference_data, ref = nil) ⇒ Object
Builds a Reference object
70 71 72 73 74 75 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 70 def build_reference(reference_data, ref = nil) ref ||= primary_index_ref return reference_data if reference_data.kind_of?(::InventoryRefresh::InventoryCollection::Reference) ::InventoryRefresh::InventoryCollection::Reference.new(reference_data, ref, named_ref(ref)) end |
#build_stringified_reference(hash, keys) ⇒ String
Builds string uuid from passed Hash and keys
82 83 84 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 82 def build_stringified_reference(hash, keys) ::InventoryRefresh::InventoryCollection::Reference.build_stringified_reference(hash, keys) end |
#build_stringified_reference_for_record(record, keys) ⇒ String
Builds string uuid from passed Object and keys
91 92 93 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 91 def build_stringified_reference_for_record(record, keys) ::InventoryRefresh::InventoryCollection::Reference.build_stringified_reference_for_record(record, keys) end |
#merge!(references_array, ref: nil) ⇒ InventoryRefresh::InventoryCollection::ReferencesStorage
Adds array of references to the storage. The reference can be already existing, otherwise we attempt to build it.
55 56 57 58 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 55 def merge!(references_array, ref: nil) references_array.each { |reference_data| add_reference(reference_data, :ref => ref) } self end |
#primary_references ⇒ Hash{String => InventoryRefresh::InventoryCollection::Reference}
Returns Hash of indexed Reference objects.
61 62 63 |
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 61 def primary_references references[primary_index_ref] end |