Sha256: 5b6b19c47873da8a9b531f007e2b67d33c3c6a0952f2436ec65a95c7f4d433c9

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require "inventory_refresh/save_collection/recursive"
require "inventory_refresh/save_collection/topological_sort"

module InventoryRefresh
  class SaveInventory
    class << self
      include Logging

      # Saves the passed InventoryCollection objects
      #
      # @param ems [ExtManagementSystem] manager owning the inventory_collections
      # @param inventory_collections [Array<InventoryRefresh::InventoryCollection>] array of InventoryCollection objects
      #        for saving
      def save_inventory(ems, inventory_collections, strategy = nil)
        logger.debug("#{log_header(ems)} Scanning Inventory Collections...Start")
        InventoryRefresh::InventoryCollection::Scanner.scan!(inventory_collections)
        logger.debug("#{log_header(ems)} Scanning Inventory Collections...Complete")

        logger.info("#{log_header(ems)} Saving EMS Inventory...")

        if strategy.try(:to_sym) == :recursive
          InventoryRefresh::SaveCollection::Recursive.save_collections(ems, inventory_collections)
        else
          InventoryRefresh::SaveCollection::TopologicalSort.save_collections(ems, inventory_collections)
        end

        logger.info("#{log_header(ems)} Saving EMS Inventory...Complete")
        ems
      end

      private

      # @param ems [ExtManagementSystem] manager owning the inventory_collections
      # @return [String] helper string for logging
      def log_header(ems)
        "EMS: [#{ems.name}], id: [#{ems.id}]"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inventory_refresh-0.1.3 lib/inventory_refresh/save_inventory.rb
inventory_refresh-0.1.2 lib/inventory_refresh/save_inventory.rb
inventory_refresh-0.1.1 lib/inventory_refresh/save_inventory.rb