Class: InventoryRefresh::InventoryCollection::ReferencesStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/inventory_refresh/inventory_collection/references_storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index_proxy) ⇒ 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_referencesSet (readonly)



10
11
12
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 10

def attribute_references
  @attribute_references
end

#referencesHash (readonly)



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



53
54
55
56
57
58
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 53

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



65
66
67
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 65

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



74
75
76
# File 'lib/inventory_refresh/inventory_collection/references_storage.rb', line 74

def build_stringified_reference_for_record(record, keys)
  ::InventoryRefresh::InventoryCollection::Reference.build_stringified_reference_for_record(record, keys)
end