Class: OCFL::InventoryWriter
- Inherits:
-
Object
- Object
- OCFL::InventoryWriter
- Defined in:
- lib/ocfl/inventory_writer.rb
Overview
Writes a OCFL Inventory to json on disk
Instance Attribute Summary collapse
-
#inventory ⇒ Object
readonly
Returns the value of attribute inventory.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #checksum_file ⇒ Object
-
#initialize(inventory:, path:) ⇒ InventoryWriter
constructor
A new instance of InventoryWriter.
- #inventory_file ⇒ Object
- #update_inventory_checksum ⇒ Object
- #write ⇒ Object
- #write_inventory ⇒ Object
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
#inventory ⇒ Object (readonly)
Returns the value of attribute inventory.
11 12 13 |
# File 'lib/ocfl/inventory_writer.rb', line 11 def inventory @inventory end |
#path ⇒ Object (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_file ⇒ Object
26 27 28 |
# File 'lib/ocfl/inventory_writer.rb', line 26 def checksum_file path / "inventory.json.sha512" end |
#inventory_file ⇒ Object
22 23 24 |
# File 'lib/ocfl/inventory_writer.rb', line 22 def inventory_file path / "inventory.json" end |
#update_inventory_checksum ⇒ Object
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 |
#write ⇒ Object
13 14 15 16 |
# File 'lib/ocfl/inventory_writer.rb', line 13 def write write_inventory update_inventory_checksum end |
#write_inventory ⇒ Object
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 |