Class: InventoryRefresh::InventoryCollection::Scanner
- Inherits:
-
Object
- Object
- InventoryRefresh::InventoryCollection::Scanner
- Defined in:
- lib/inventory_refresh/inventory_collection/scanner.rb
Instance Attribute Summary collapse
-
#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
-
.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) ⇒ Scanner
constructor
A new instance of Scanner.
- #scan! ⇒ Object
Constructor Details
#initialize(inventory_collection, indexed_inventory_collections) ⇒ Scanner
53 54 55 56 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 53 def initialize(inventory_collection, indexed_inventory_collections) @inventory_collection = inventory_collection @indexed_inventory_collections = indexed_inventory_collections end |
Instance Attribute Details
#indexed_inventory_collections ⇒ Object (readonly)
Returns the value of attribute indexed_inventory_collections.
27 28 29 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 27 def indexed_inventory_collections @indexed_inventory_collections end |
#inventory_collection ⇒ Object (readonly)
Returns the value of attribute inventory_collection.
27 28 29 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 27 def inventory_collection @inventory_collection end |
Class Method Details
.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).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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/inventory_refresh/inventory_collection/scanner.rb', line 58 def scan! # Scan InventoryCollection InventoryObjects and store the results inside of the InventoryCollection data.each do |inventory_object| scan_inventory_object!(inventory_object) if targeted? && parent_inventory_collections.blank? # We want to track what manager_uuids we should query from a db, for the targeted refresh targeted_scope << inventory_object.reference end end # Transform :parent_inventory_collections symbols to InventoryCollection objects if parent_inventory_collections.present? self.parent_inventory_collections = parent_inventory_collections.map do |inventory_collection_index| ic = indexed_inventory_collections[inventory_collection_index] if ic.nil? raise "Can't find InventoryCollection #{inventory_collection_index} from #{inventory_collection}" if targeted? else # Add parent_inventory_collection as a dependency, so e.g. disconnect is done in a right order (dependency_attributes[:__parent_inventory_collections] ||= Set.new) << ic ic end end.compact end # Mark InventoryCollection as finalized aka. scanned self.data_collection_finalized = true end |