Class: OcflTools::OcflDeposit
- Inherits:
-
OcflInventory
- Object
- OcflObject
- OcflInventory
- OcflTools::OcflDeposit
- Defined in:
- lib/ocfl_tools/ocfl_deposit.rb
Overview
Class to take new content from a deposit directory and marshal it into a new version directory of a new or existing OCFL object dir. Expects deposit_dir to be:
<ocfl deposit directoy>/
|-- inventory.json (from object_directory root, if adding to existing version)
|-- inventory.json.sha512 (matching sidecar from object_directory root)
|-- head/
|-- head.json
| OR a combination of the following files:
|-- add_files.json (all proposed file add actions)
|-- update_files.json (all proposed file update actions)
|-- copy_files.json (all proposed file copy actions)
|-- delete_files.json (all proposed file delete actions)
|-- move_files.json (all proposed file move actions)
|-- version.json (optional version metadata)
|-- fixity_files.json (optional fixity information)
|-- <content_dir>/
|-- <files to add or update>
Instance Attribute Summary collapse
-
#ocfl_version ⇒ String
The version of OCFL that this deposit object is targeting.
Attributes inherited from OcflObject
#contentDirectory, #digestAlgorithm, #fixity, #head, #id, #manifest, #type, #versions
Instance Method Summary collapse
-
#deposit_new_version ⇒ OcflTools::OcflDeposit
Creates a new version of an OCFL object in the destination object directory.
- #initialize(deposit_directory:, object_directory:) ⇒ OcflTools::OcflDeposit constructor
-
#results ⇒ OcflTools::OcflResults
Returns a OcflResults object containing information about actions taken during the staging and creation of this new version.
Methods inherited from OcflInventory
#from_file, #read_json, #serialize, #set_head_version, #to_file
Methods inherited from OcflObject
#add_file, #copy_file, #create_version_hash, #delete_file, #get_current_files, #get_digest, #get_files, #get_state, #get_version, #get_version_created, #get_version_message, #get_version_user, #move_file, #set_head_from_version, #set_state, #set_version, #set_version_created, #set_version_message, #set_version_user, #update_file, #update_fixity, #update_manifest, #version_id_list
Constructor Details
#initialize(deposit_directory:, object_directory:) ⇒ OcflTools::OcflDeposit
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ocfl_tools/ocfl_deposit.rb', line 32 def initialize(deposit_directory:, object_directory:) @deposit_dir = deposit_directory @object_dir = object_directory unless File.directory? deposit_directory raise "#{@deposit_dir} is not a valid directory!" end unless File.directory? object_directory raise "#{@object_dir} is not a valid directory!" end # Since we are overriding OcflObject's initialize block, we need to define these variables again. @id = nil @head = nil @type = OcflTools.config.content_type @digestAlgorithm = OcflTools.config.digest_algorithm # sha512 is recommended, Stanford uses sha256. @contentDirectory = OcflTools.config.content_directory # default is 'content', Stanford uses 'data' @manifest = {} @versions = {} # A hash of Version hashes. @fixity = {} # Optional. Same format as Manifest. @ocfl_version = nil @my_results = OcflTools::OcflResults.new # san_check works out if the deposit_dir and object_dir represents a # new object with a first version, or an update to an existing object. # It then verifies and stages all files so that, if it doesn't raise an # exception, the calling app can simply invoke #deposit_new_version to proceed. san_check end |
Instance Attribute Details
#ocfl_version ⇒ String
Returns the version of OCFL that this deposit object is targeting.
27 28 29 |
# File 'lib/ocfl_tools/ocfl_deposit.rb', line 27 def ocfl_version @ocfl_version end |
Instance Method Details
#deposit_new_version ⇒ OcflTools::OcflDeposit
Creates a new version of an OCFL object in the destination object directory. This method can only be called if the OcflTools::OcflDeposit object passed all necessary sanity checks, which occur when the object is initialized.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ocfl_tools/ocfl_deposit.rb', line 73 def deposit_new_version # verify that our object_directory head is still what we expect. # create the version and contentDirectory directories. # move or copy content over from deposit_directory # write the inventory.json & sidecar into version directory. # do a directory verify on the new directory. # write the new inventory.json to object root. # Can only be called if there are no errors in @my_results; raise exception if otherwise? set_head_version # Am I put together correctly? @my_results.add_results(OcflTools::OcflVerify.new(self).check_all) # If @my_results.error_count > 0, abort! if @my_results.error_count > 0 raise "Errors detected in OCFL object verification. Cannot process deposit: #{@my_results.get_errors}" end if OcflTools::Utils.version_string_to_int(@head) == 1 && !Dir.empty?(@object_dir) raise "#{@object_dir} is not empty! Unable to create new object." end process_new_version self end |
#results ⇒ OcflTools::OcflResults
Returns a OcflTools::OcflResults object containing information about actions taken during the staging and creation of this new version.
65 66 67 |
# File 'lib/ocfl_tools/ocfl_deposit.rb', line 65 def results @my_results end |