Class: Moose::Inventory::Operations::ImportInventorySnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/moose_inventory/operations/import_inventory_snapshot.rb

Overview

Validates and imports a portable inventory snapshot.

Constant Summary collapse

Result =
InventorySnapshotApplier::Result

Instance Method Summary collapse

Constructor Details

#initialize(context:) ⇒ ImportInventorySnapshot

Returns a new instance of ImportInventorySnapshot.



14
15
16
17
18
19
# File 'lib/moose_inventory/operations/import_inventory_snapshot.rb', line 14

def initialize(context:)
  @context = context
  @validator = InventorySnapshotValidator.new(context: context)
  @applier = InventorySnapshotApplier.new(context: context)
  @previewer = InventorySnapshotPreview.new(context: context)
end

Instance Method Details

#call(snapshot:) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/moose_inventory/operations/import_inventory_snapshot.rb', line 21

def call(snapshot:)
  normalized = validator.call(snapshot: snapshot)

  context.transaction do
    applier.call(snapshot: normalized)
  end
end

#preview(snapshot:) ⇒ Object



29
30
31
32
33
# File 'lib/moose_inventory/operations/import_inventory_snapshot.rb', line 29

def preview(snapshot:)
  normalized = validator.call(snapshot: snapshot)

  previewer.call(snapshot: normalized)
end