Class: OCFL::InventoryWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/ocfl/inventory_writer.rb

Overview

Writes a OCFL Inventory to json on disk

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inventory:, path:) ⇒ InventoryWriter

Returns a new instance of InventoryWriter.



6
7
8
9
# File 'lib/ocfl/inventory_writer.rb', line 6

def initialize(inventory:, path:)
  @path = path
  @inventory = inventory
end

Instance Attribute Details

#inventoryObject (readonly)

Returns the value of attribute inventory.



11
12
13
# File 'lib/ocfl/inventory_writer.rb', line 11

def inventory
  @inventory
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/ocfl/inventory_writer.rb', line 11

def path
  @path
end

Instance Method Details

#checksum_fileObject



26
27
28
# File 'lib/ocfl/inventory_writer.rb', line 26

def checksum_file
  path / "inventory.json.sha512"
end

#inventory_fileObject



22
23
24
# File 'lib/ocfl/inventory_writer.rb', line 22

def inventory_file
  path / "inventory.json"
end

#update_inventory_checksumObject



30
31
32
33
# File 'lib/ocfl/inventory_writer.rb', line 30

def update_inventory_checksum
  digest = Digest::SHA512.file inventory_file
  File.write(checksum_file, "#{digest} inventory.json")
end

#writeObject



13
14
15
16
# File 'lib/ocfl/inventory_writer.rb', line 13

def write
  write_inventory
  update_inventory_checksum
end

#write_inventoryObject



18
19
20
# File 'lib/ocfl/inventory_writer.rb', line 18

def write_inventory
  File.write(inventory_file, JSON.pretty_generate(inventory.to_h))
end