Sha256: 56e127da94965a50a767c718d57be5712619022c4a1853eb3c15917f5ddde8ac

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require "inventory_refresh/logging"
require "inventory_refresh/save_collection/saver/batch"
require "inventory_refresh/save_collection/saver/concurrent_safe"
require "inventory_refresh/save_collection/saver/concurrent_safe_batch"
require "inventory_refresh/save_collection/saver/default"

module InventoryRefresh::SaveCollection
  class Base
    class << self
      include InventoryRefresh::Logging

      # Saves one InventoryCollection object into the DB.
      #
      # @param ems [ExtManagementSystem] manger owning the InventoryCollection object
      # @param inventory_collection [InventoryRefresh::InventoryCollection] InventoryCollection object we want to save
      def save_inventory_object_inventory(ems, inventory_collection)
        log.debug("Saving collection #{inventory_collection} of size #{inventory_collection.size} to"\
                  " the database, for the manager: '#{ems.name}'...")

        if inventory_collection.custom_save_block.present?
          log.debug("Saving collection #{inventory_collection} using a custom save block")
          inventory_collection.custom_save_block.call(ems, inventory_collection)
        else
          save_inventory(inventory_collection)
        end
        log.debug("Saving collection #{inventory_collection}, for the manager: '#{ems.name}'...Complete")
        inventory_collection.saved = true
      end

      private

      # Saves one InventoryCollection object into the DB using a configured saver_strategy class.
      #
      # @param inventory_collection [InventoryRefresh::InventoryCollection] InventoryCollection object we want to save
      def save_inventory(inventory_collection)
        saver_class = "InventoryRefresh::SaveCollection::Saver::#{inventory_collection.saver_strategy.to_s.camelize}"
        saver_class.constantize.new(inventory_collection).save_inventory_collection!
      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_collection/base.rb