Class: InventoryRefresh::InventoryCollection::Index::Type::Skeletal
- Defined in:
- lib/inventory_refresh/inventory_collection/index/type/skeletal.rb
Instance Method Summary collapse
-
#build(attributes) ⇒ InventoryObject
Builds index record with skeletal InventoryObject and returns it.
-
#delete(index_value) ⇒ InventoryObject|nil
Deletes and returns the value on the index_value.
-
#find(index_value) ⇒ InventoryObject|nil
Find value based on index_value.
-
#initialize(inventory_collection, index_name, attribute_names, primary_index) ⇒ Skeletal
constructor
A new instance of Skeletal.
-
#skeletonize_primary_index(index_value) ⇒ InventoryObject|nil
Takes value from primary_index and inserts it to skeletal index.
Methods inherited from Base
Constructor Details
#initialize(inventory_collection, index_name, attribute_names, primary_index) ⇒ Skeletal
Returns a new instance of Skeletal.
11 12 13 14 15 |
# File 'lib/inventory_refresh/inventory_collection/index/type/skeletal.rb', line 11 def initialize(inventory_collection, index_name, attribute_names, primary_index) super @primary_index = primary_index end |
Instance Method Details
#build(attributes) ⇒ InventoryObject
Builds index record with skeletal InventoryObject and returns it. Or it returns existing InventoryObject that is found in primary_index or skeletal_primary_index.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/inventory_refresh/inventory_collection/index/type/skeletal.rb', line 62 def build(attributes) attributes = {}.merge!(default_values).merge!(attributes) fill_versions!(attributes) # If the primary index is already filled, we don't want populate skeletal index uuid = ::InventoryRefresh::InventoryCollection::Reference.build_stringified_reference(attributes, named_ref) if (inventory_object = primary_index.find(uuid)) return inventory_object.assign_attributes(attributes) end # Return if skeletal index already exists if (inventory_object = index[uuid]) return inventory_object.assign_attributes(attributes) end # We want to populate a new skeletal index inventory_object = new_inventory_object(attributes) index[inventory_object.manager_uuid] = inventory_object end |
#delete(index_value) ⇒ InventoryObject|nil
Deletes and returns the value on the index_value
39 40 41 |
# File 'lib/inventory_refresh/inventory_collection/index/type/skeletal.rb', line 39 def delete(index_value) index.delete(index_value) end |
#find(index_value) ⇒ InventoryObject|nil
Find value based on index_value
31 32 33 |
# File 'lib/inventory_refresh/inventory_collection/index/type/skeletal.rb', line 31 def find(index_value) index[index_value] end |
#skeletonize_primary_index(index_value) ⇒ InventoryObject|nil
Takes value from primary_index and inserts it to skeletal index
47 48 49 50 51 52 53 |
# File 'lib/inventory_refresh/inventory_collection/index/type/skeletal.rb', line 47 def skeletonize_primary_index(index_value) inventory_object = primary_index.delete(index_value) return unless inventory_object fill_versions!(inventory_object.data) index[index_value] = inventory_object end |