Class: OCFL::Object
- Inherits:
-
Object
- Object
- OCFL::Object
- Defined in:
- lib/ocfl/object.rb
Overview
An OCFL Object is a group of one or more content files and administrative information ocfl.io/1.1/spec/#object-spec
Defined Under Namespace
Classes: FileNotFound
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#begin_new_version ⇒ Object
Start a completely new version.
- #exists? ⇒ Boolean
- #head_directory_valid? ⇒ Boolean
- #head_inventory ⇒ Object
-
#head_version ⇒ Object
Get a handle for the head version.
-
#initialize(root:, identifier:, inventory: nil, content_directory: nil) ⇒ Object
constructor
A new instance of Object.
- #inventory ⇒ Object
- #namaste_file ⇒ Object
-
#overwrite_current_version ⇒ Object
Get a handle that will replace the existing head version.
- #path(filepath:, version: nil) ⇒ Object
- #reload ⇒ Object
- #valid? ⇒ Boolean
- #version_inventory(version) ⇒ Object
Constructor Details
#initialize(root:, identifier:, inventory: nil, content_directory: nil) ⇒ Object
Returns a new instance of Object.
13 14 15 16 17 18 19 20 |
# File 'lib/ocfl/object.rb', line 13 def initialize(root:, identifier:, inventory: nil, content_directory: nil) @identifier = identifier @root = Pathname.new(root) @content_directory = content_directory @version_inventory = {} @version_inventory_errors = {} @inventory = inventory end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
22 23 24 |
# File 'lib/ocfl/object.rb', line 22 def errors @errors end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
22 23 24 |
# File 'lib/ocfl/object.rb', line 22 def identifier @identifier end |
Instance Method Details
#begin_new_version ⇒ Object
Start a completely new version
82 83 84 |
# File 'lib/ocfl/object.rb', line 82 def begin_new_version VersionBuilder.new(object: self, state:) end |
#exists? ⇒ Boolean
26 27 28 |
# File 'lib/ocfl/object.rb', line 26 def exists? namaste_file.exist? end |
#head_directory_valid? ⇒ Boolean
76 77 78 79 |
# File 'lib/ocfl/object.rb', line 76 def head_directory_valid? InventoryValidator.new(directory: root / inventory.head).valid? && !head_inventory.nil? # Ensures it could be loaded end |
#head_inventory ⇒ Object
52 53 54 |
# File 'lib/ocfl/object.rb', line 52 def head_inventory version_inventory(inventory.head) end |
#head_version ⇒ Object
Get a handle for the head version
87 88 89 |
# File 'lib/ocfl/object.rb', line 87 def head_version VersionBuilder.new(object: self, overwrite_head: true, state: head_inventory.state) end |
#inventory ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ocfl/object.rb', line 39 def inventory @inventory ||= begin maybe_inventory, inventory_loading_errors = load_or_initialize_inventory if maybe_inventory maybe_inventory else @errors = inventory_loading_errors puts @errors..inspect nil end end end |
#namaste_file ⇒ Object
104 105 106 |
# File 'lib/ocfl/object.rb', line 104 def namaste_file root / "0=ocfl_object_1.1" end |
#overwrite_current_version ⇒ Object
Get a handle that will replace the existing head version
92 93 94 |
# File 'lib/ocfl/object.rb', line 92 def overwrite_current_version VersionBuilder.new(object: self, overwrite_head: true) end |
#path(filepath:, version: nil) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/ocfl/object.rb', line 30 def path(filepath:, version: nil) version ||= head relative_path = version_inventory(version).path(filepath) raise FileNotFound, "Path '#{filepath}' not found in #{version} inventory" if relative_path.nil? root / relative_path end |
#reload ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/ocfl/object.rb', line 96 def reload @version_inventory = {} @inventory = nil @errors = nil @version_inventory_errors = {} true end |
#valid? ⇒ Boolean
69 70 71 72 73 74 |
# File 'lib/ocfl/object.rb', line 69 def valid? InventoryValidator.new(directory: root).valid? && exists? && !inventory.nil? && # Ensures it could be loaded head_directory_valid? end |
#version_inventory(version) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ocfl/object.rb', line 56 def version_inventory(version) @version_inventory[version] ||= begin maybe_inventory, inventory_loading_errors = load_or_initialize_inventory(version:) if maybe_inventory maybe_inventory else @version_inventory_errors[version] = inventory_loading_errors puts @version_inventory_errors[version]..inspect nil end end end |