Class: InventoryRefresh::InventoryCollection::Index::Proxy
- Inherits:
-
Object
- Object
- InventoryRefresh::InventoryCollection::Index::Proxy
- Includes:
- Logging
- Defined in:
- lib/inventory_refresh/inventory_collection/index/proxy.rb
Instance Attribute Summary collapse
-
#skeletal_primary_index ⇒ Object
readonly
Returns the value of attribute skeletal_primary_index.
Instance Method Summary collapse
-
#build_primary_index_for(inventory_object) ⇒ InventoryRefresh::InventoryObject
Builds primary index for passed InventoryObject.
- #build_secondary_indexes_for(inventory_object) ⇒ Object
- #find(reference, ref: primary_index_ref) ⇒ Object
-
#initialize(inventory_collection, secondary_refs = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #lazy_find(manager_uuid, ref: primary_index_ref, key: nil, default: nil, transform_nested_lazy_finds: false) ⇒ Object
- #named_ref(ref = primary_index_ref) ⇒ Object
- #primary_index ⇒ Object
- #primary_index_ref ⇒ Object
Methods included from Logging
Constructor Details
#initialize(inventory_collection, secondary_refs = {}) ⇒ Proxy
Returns a new instance of Proxy.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 17 def initialize(inventory_collection, secondary_refs = {}) @inventory_collection = inventory_collection @primary_ref = {primary_index_ref => @inventory_collection.manager_ref} @secondary_refs = secondary_refs @all_refs = @primary_ref.merge(@secondary_refs) @data_indexes = {} @local_db_indexes = {} @all_refs.each do |index_name, attribute_names| @data_indexes[index_name] = InventoryRefresh::InventoryCollection::Index::Type::Data.new( inventory_collection, index_name, attribute_names ) @local_db_indexes[index_name] = InventoryRefresh::InventoryCollection::Index::Type::LocalDb.new( inventory_collection, index_name, attribute_names, @data_indexes[index_name] ) end @skeletal_primary_index = InventoryRefresh::InventoryCollection::Index::Type::Skeletal.new( inventory_collection, :skeletal_primary_index_ref, named_ref, primary_index ) end |
Instance Attribute Details
#skeletal_primary_index ⇒ Object (readonly)
Returns the value of attribute skeletal_primary_index.
13 14 15 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 13 def skeletal_primary_index @skeletal_primary_index end |
Instance Method Details
#build_primary_index_for(inventory_object) ⇒ InventoryRefresh::InventoryObject
Builds primary index for passed InventoryObject
54 55 56 57 58 59 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 54 def build_primary_index_for(inventory_object) # Building the object, we need to provide all keys of a primary index assert_index(inventory_object.data, primary_index_ref) primary_index.store_index_for(inventory_object) end |
#build_secondary_indexes_for(inventory_object) ⇒ Object
61 62 63 64 65 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 61 def build_secondary_indexes_for(inventory_object) secondary_refs.keys.each do |ref| data_index(ref).store_index_for(inventory_object) end end |
#find(reference, ref: primary_index_ref) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 71 def find(reference, ref: primary_index_ref) # TODO(lsmola) lazy_find will support only hash, then we can remove the _by variant # TODO(lsmola) this method should return lazy too, the rest of the finders should be deprecated return if reference.nil? assert_index(reference, ref) reference = inventory_collection.build_reference(reference, ref) case strategy when :local_db_find_references, :local_db_cache_all local_db_index_find(reference) when :local_db_find_missing_references find_in_data_or_skeletal_index(reference) || local_db_index_find(reference) else find_in_data_or_skeletal_index(reference) end end |
#lazy_find(manager_uuid, ref: primary_index_ref, key: nil, default: nil, transform_nested_lazy_finds: false) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 89 def lazy_find(manager_uuid, ref: primary_index_ref, key: nil, default: nil, transform_nested_lazy_finds: false) return if manager_uuid.nil? assert_index(manager_uuid, ref) ::InventoryRefresh::InventoryObjectLazy.new(inventory_collection, manager_uuid, :ref => ref, :key => key, :default => default, :transform_nested_lazy_finds => transform_nested_lazy_finds) end |
#named_ref(ref = primary_index_ref) ⇒ Object
101 102 103 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 101 def named_ref(ref = primary_index_ref) all_refs[ref] end |
#primary_index ⇒ Object
67 68 69 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 67 def primary_index data_index(primary_index_ref) end |
#primary_index_ref ⇒ Object
105 106 107 |
# File 'lib/inventory_refresh/inventory_collection/index/proxy.rb', line 105 def primary_index_ref :manager_ref end |