Class: InventoryRefresh::InventoryCollection::Scanner
- Inherits:
-
Object
- Object
- InventoryRefresh::InventoryCollection::Scanner
- Defined in:
- lib/inventory_refresh/inventory_collection/scanner.rb
Instance Attribute Summary collapse
-
#associations_hash ⇒ Object
readonly
Returns the value of attribute associations_hash.
-
#indexed_inventory_collections ⇒ Object
readonly
Returns the value of attribute indexed_inventory_collections.
-
#inventory_collection ⇒ Object
readonly
Returns the value of attribute inventory_collection.
Class Method Summary collapse
- .build_association_hash(inventory_collections) ⇒ Object
-
.scan!(inventory_collections) ⇒ Object
Scanning inventory_collections for dependencies and references, storing the results in the inventory_collections themselves.
Instance Method Summary collapse
-
#initialize(inventory_collection, indexed_inventory_collections, associations_hash) ⇒ Scanner
constructor
A new instance of Scanner.
- #scan! ⇒ Object
Constructor Details
#initialize(inventory_collection, indexed_inventory_collections, associations_hash) ⇒ Scanner
Returns a new instance of Scanner.
65 66 67 68 69 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 65 def initialize(inventory_collection, indexed_inventory_collections, associations_hash) @inventory_collection = inventory_collection @indexed_inventory_collections = indexed_inventory_collections @associations_hash = associations_hash end |
Instance Attribute Details
#associations_hash ⇒ Object (readonly)
Returns the value of attribute associations_hash.
39 40 41 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 39 def associations_hash @associations_hash end |
#indexed_inventory_collections ⇒ Object (readonly)
Returns the value of attribute indexed_inventory_collections.
39 40 41 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 39 def indexed_inventory_collections @indexed_inventory_collections end |
#inventory_collection ⇒ Object (readonly)
Returns the value of attribute inventory_collection.
39 40 41 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 39 def inventory_collection @inventory_collection end |
Class Method Details
.build_association_hash(inventory_collections) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 26 def build_association_hash(inventory_collections) associations_hash = {} parents = inventory_collections.map(&:parent).compact.uniq parents.each do |parent| parent.class.reflect_on_all_associations(:has_many).each do |association| through_assoc = association..try(:[], :through) associations_hash[association.name] = through_assoc if association..try(:[], :through) end end associations_hash end |
.scan!(inventory_collections) ⇒ Object
Scanning inventory_collections for dependencies and references, storing the results in the inventory_collections themselves. Dependencies are needed for building a graph, references are needed for effective DB querying, where we can load all referenced objects of some InventoryCollection by one DB query.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 12 def scan!(inventory_collections) indexed_inventory_collections = inventory_collections.index_by(&:name) inventory_collections.each do |inventory_collection| new(inventory_collection, indexed_inventory_collections, build_association_hash(inventory_collections)).scan! end inventory_collections.each do |inventory_collection| inventory_collection.dependencies.each do |dependency| dependency.dependees << inventory_collection end end end |
Instance Method Details
#scan! ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 71 def scan! # Scan InventoryCollection InventoryObjects and store the results inside of the InventoryCollection data.each do |inventory_object| scan_inventory_object!(inventory_object) end # Scan InventoryCollection skeletal data inventory_collection.skeletal_primary_index.each_value do |inventory_object| scan_inventory_object!(inventory_object) end # Mark InventoryCollection as finalized aka. scanned self.data_collection_finalized = true end |