Sha256: 10d3398b5f648958fe48c6f93fc386358e0dd75c0f48d8326da403e3842026ac

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 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)
        log.debug("#{log_header(ems)} Scanning Inventory Collections...Start")
        InventoryRefresh::InventoryCollection::Scanner.scan!(inventory_collections)
        log.debug("#{log_header(ems)} Scanning Inventory Collections...Complete")

        log.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

        log.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

1 entries across 1 versions & 1 rubygems

Version Path
inventory_refresh-0.1.0 lib/inventory_refresh/save_inventory.rb