Class: OCFL::InventoryValidator
- Inherits:
-
Object
- Object
- OCFL::InventoryValidator
- Defined in:
- lib/ocfl/inventory_validator.rb
Overview
Checks to see that the inventory.json and it’s checksum in a direcotory are valid
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
-
#initialize(directory:) ⇒ InventoryValidator
constructor
A new instance of InventoryValidator.
- #inventory_checksum_file ⇒ Object
- #inventory_file ⇒ Object
- #inventory_file_checksum ⇒ Object
- #inventory_file_exists? ⇒ Boolean
- #inventory_file_matches_checksum? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(directory:) ⇒ InventoryValidator
Returns a new instance of InventoryValidator.
6 7 8 |
# File 'lib/ocfl/inventory_validator.rb', line 6 def initialize(directory:) @directory = Pathname.new(directory) end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
10 11 12 |
# File 'lib/ocfl/inventory_validator.rb', line 10 def directory @directory end |
Instance Method Details
#inventory_checksum_file ⇒ Object
28 29 30 |
# File 'lib/ocfl/inventory_validator.rb', line 28 def inventory_checksum_file directory / "inventory.json.sha512" end |
#inventory_file ⇒ Object
36 37 38 |
# File 'lib/ocfl/inventory_validator.rb', line 36 def inventory_file directory / "inventory.json" end |
#inventory_file_checksum ⇒ Object
32 33 34 |
# File 'lib/ocfl/inventory_validator.rb', line 32 def inventory_file_checksum Digest::SHA512.file inventory_file end |
#inventory_file_exists? ⇒ Boolean
16 17 18 |
# File 'lib/ocfl/inventory_validator.rb', line 16 def inventory_file_exists? File.exist?(inventory_file) end |
#inventory_file_matches_checksum? ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/ocfl/inventory_validator.rb', line 20 def inventory_file_matches_checksum? return false unless File.exist?(inventory_checksum_file) actual = inventory_file_checksum expected = File.read(inventory_checksum_file) expected.match?(/\A#{actual}\s+inventory\.json\z/) end |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/ocfl/inventory_validator.rb', line 12 def valid? inventory_file_exists? && inventory_file_matches_checksum? end |