ocfl 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/ocfl/object/directory.rb +1 -1
- data/lib/ocfl/object/directory_builder.rb +2 -2
- data/lib/ocfl/object/draft_version.rb +23 -6
- data/lib/ocfl/version.rb +1 -1
- data/lib/ocfl.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b1b7553fa1d862a3aa1f6a7f63b148f424f1448c321f7b534776c857ce932f2
|
4
|
+
data.tar.gz: 8408cf71f4a08fc2c44485ea69e6f77eb5e49366a80d460d20e7ab7961ef9442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5420543eb4d07840970600fbc1f4a475e2ae3f09dea57de76087e626ed87a99ec9b02cf4dd38598398fb75aaa1e8eb61fb20d2af4d4b2b9939a269cf811d7b13
|
7
|
+
data.tar.gz: f3f6b84156e307897c3be76ed247043ce5d5f161536267b2ee5cfb8a91b50c6080da57ba6fc5c063349603784a13689ef4bbc74c624cbf302ec3f50810b53307
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ directory = OCFL::Object::Directory.new(object_root: '/files/[object_root]')
|
|
20
20
|
directory.exists?
|
21
21
|
# => false
|
22
22
|
builder = OCFL::Object::DirectoryBuilder.new(object_root: 'spec/abc123', id: 'http://example.com/abc123')
|
23
|
-
builder.copy_file('sig/ocfl.rbs')
|
23
|
+
builder.copy_file('sig/ocfl.rbs', destination_path: 'ocfl/types/generated.rbs')
|
24
24
|
|
25
25
|
directory = builder.save
|
26
26
|
directory.exists?
|
@@ -43,10 +43,10 @@ directory.head
|
|
43
43
|
# => 'v2'
|
44
44
|
```
|
45
45
|
|
46
|
-
####
|
46
|
+
#### Modify the existing head version
|
47
47
|
```
|
48
|
-
new_version = directory.
|
49
|
-
new_version.delete_file('
|
48
|
+
new_version = directory.head_version
|
49
|
+
new_version.delete_file('sample.txt')
|
50
50
|
new_version.copy_file('sig/ocfl.rbs')
|
51
51
|
new_version.save
|
52
52
|
```
|
@@ -64,6 +64,10 @@ new_version.save
|
|
64
64
|
directory.versions['v2'].file_names
|
65
65
|
# => ["ocfl.rbs"]
|
66
66
|
|
67
|
+
# Or on the head version
|
68
|
+
directory.head_version.file_names
|
69
|
+
# => ["ocfl.rbs"]
|
70
|
+
|
67
71
|
# Get the path of a file in a given version
|
68
72
|
directory.path(filepath: "ocfl.rbs", version: "v2")
|
69
73
|
# => <Pathname:/files/[object_root]/v2/content/ocfl.rbs>
|
@@ -33,12 +33,12 @@ module OCFL
|
|
33
33
|
|
34
34
|
def create_object_directory
|
35
35
|
FileUtils.mkdir_p(object_root)
|
36
|
+
FileUtils.touch(object_directory.namaste_file) unless File.exist?(object_directory.namaste_file)
|
36
37
|
end
|
37
38
|
|
38
39
|
# @return [Directory]
|
39
40
|
def save
|
40
|
-
|
41
|
-
FileUtils.touch(object_directory.namaste_file)
|
41
|
+
create_object_directory
|
42
42
|
write_inventory
|
43
43
|
object_directory
|
44
44
|
end
|
@@ -17,6 +17,8 @@ module OCFL
|
|
17
17
|
|
18
18
|
attr_reader :object_directory, :manifest, :state, :version_number
|
19
19
|
|
20
|
+
delegate :file_names, to: :to_version_struct
|
21
|
+
|
20
22
|
def move_file(incoming_path)
|
21
23
|
prepare_content_directory
|
22
24
|
add(incoming_path)
|
@@ -25,11 +27,18 @@ module OCFL
|
|
25
27
|
|
26
28
|
def copy_file(incoming_path, destination_path: "")
|
27
29
|
prepare_content_directory
|
28
|
-
copy_one(File.basename(incoming_path), incoming_path
|
30
|
+
copy_one(destination_path.presence || File.basename(incoming_path), incoming_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def digest_for_filename(filename)
|
34
|
+
state.find { |_, filenames| filenames.include?(filename) }&.first
|
29
35
|
end
|
30
36
|
|
31
37
|
# Note, this only removes the file from this version. Previous versions may still use it.
|
32
|
-
def delete_file(
|
38
|
+
def delete_file(filename)
|
39
|
+
sha512_digest = digest_for_filename(filename)
|
40
|
+
raise "Unknown file: #{filename}" unless sha512_digest
|
41
|
+
|
33
42
|
state.delete(sha512_digest)
|
34
43
|
# If the manifest points at the current content directory, then we can delete it.
|
35
44
|
file_paths = manifest[sha512_digest]
|
@@ -43,7 +52,10 @@ module OCFL
|
|
43
52
|
prepare_content_directory
|
44
53
|
incoming_path = incoming_path.delete_suffix("/")
|
45
54
|
Dir.glob("#{incoming_path}/**/*").reject { |fn| File.directory?(fn) }.each do |file|
|
46
|
-
|
55
|
+
logical_file_path = file.delete_prefix(incoming_path).delete_prefix("/")
|
56
|
+
logical_file_path = File.join(destination_path, logical_file_path) unless destination_path.empty?
|
57
|
+
|
58
|
+
copy_one(logical_file_path, file)
|
47
59
|
end
|
48
60
|
end
|
49
61
|
|
@@ -53,6 +65,10 @@ module OCFL
|
|
53
65
|
object_directory.reload
|
54
66
|
end
|
55
67
|
|
68
|
+
def to_version_struct
|
69
|
+
Version.new(state:, created: Time.now.utc.iso8601)
|
70
|
+
end
|
71
|
+
|
56
72
|
private
|
57
73
|
|
58
74
|
def write_inventory(inventory)
|
@@ -61,8 +77,9 @@ module OCFL
|
|
61
77
|
FileUtils.cp(path / "inventory.json.sha512", object_directory.object_root)
|
62
78
|
end
|
63
79
|
|
64
|
-
|
65
|
-
|
80
|
+
# @param [String] logical_file_path where we're going to store the file (e.g. 'object/directory_builder_spec.rb')
|
81
|
+
# @param [String] incoming_path where's this file from (e.g. 'spec/ocfl/object/directory_builder_spec.rb')
|
82
|
+
def copy_one(logical_file_path, incoming_path)
|
66
83
|
add(incoming_path, logical_file_path:)
|
67
84
|
parent_dir = (content_path / logical_file_path).parent
|
68
85
|
FileUtils.mkdir_p(parent_dir) unless parent_dir == content_path
|
@@ -112,7 +129,7 @@ module OCFL
|
|
112
129
|
# This gives the update list of versions. The old list plus this new one.
|
113
130
|
# @param [Hash] old_versions the versions prior to this one.
|
114
131
|
def versions(old_versions)
|
115
|
-
old_versions.merge(version_number =>
|
132
|
+
old_versions.merge(version_number => to_version_struct)
|
116
133
|
end
|
117
134
|
|
118
135
|
# The manifest after unused SHAs have been filtered out.
|
data/lib/ocfl/version.rb
CHANGED
data/lib/ocfl.rb
CHANGED