ocfl 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/ocfl/object/directory.rb +5 -1
- data/lib/ocfl/object/directory_builder.rb +7 -2
- data/lib/ocfl/object/draft_version.rb +36 -18
- data/lib/ocfl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a442976eed04ea8bd466b2a423d99e18e3de2eace9950419102a26762a0f279
|
4
|
+
data.tar.gz: 998da7270a92ba987015aed961ce9d07571c9e97bdd8fb739ebce53409f0f6cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9649b239dcd0d542e772eefcc1a177eb6c9a3367a347a05277661ff5605bfd1713f7610a8b0411852c2665b594a392d6db8f2248e3d9a3578bff7bce6b4f8240
|
7
|
+
data.tar.gz: db00dc92ce3bad0b059f45f90d4ff59162d6a7532aee3160406d1088fbfcb4cf274617e4d1781577a3c1f47992f0b8109ac24226f00043b9aec0799984048189
|
data/README.md
CHANGED
@@ -5,15 +5,13 @@ This is an implementation of the Oxford Common File Layout (OCFL) for Ruby. See
|
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
8
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
9
|
-
|
10
8
|
Install the gem and add to the application's Gemfile by executing:
|
11
9
|
|
12
|
-
$ bundle add
|
10
|
+
$ bundle add ocfl
|
13
11
|
|
14
12
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
15
13
|
|
16
|
-
$ gem install
|
14
|
+
$ gem install ocfl
|
17
15
|
|
18
16
|
## Usage
|
19
17
|
|
@@ -42,6 +40,10 @@ directory.path("v2", "ocfl.rbs")
|
|
42
40
|
|
43
41
|
directory.path(:head, "ocfl.rbs")
|
44
42
|
# => <Pathname:/files/[object_root]/v2/content/ocfl.rbs>
|
43
|
+
|
44
|
+
new_version = directory.overwrite_current_version
|
45
|
+
new_version.copy_file('sig/ocfl.rbs')
|
46
|
+
new_version.save
|
45
47
|
```
|
46
48
|
|
47
49
|
## Development
|
@@ -17,7 +17,7 @@ module OCFL
|
|
17
17
|
|
18
18
|
attr_reader :object_root, :errors
|
19
19
|
|
20
|
-
delegate :head, to: :inventory
|
20
|
+
delegate :head, :versions, :manifest, to: :inventory
|
21
21
|
|
22
22
|
def path(version, filename)
|
23
23
|
version = head if version == :head
|
@@ -66,6 +66,10 @@ module OCFL
|
|
66
66
|
DraftVersion.new(object_directory: self)
|
67
67
|
end
|
68
68
|
|
69
|
+
def overwrite_current_version
|
70
|
+
DraftVersion.new(object_directory: self, overwrite_head: true)
|
71
|
+
end
|
72
|
+
|
69
73
|
def exists?
|
70
74
|
namaste_exists?
|
71
75
|
end
|
@@ -18,11 +18,16 @@ module OCFL
|
|
18
18
|
attr_reader :id, :object_root, :object_directory
|
19
19
|
|
20
20
|
def copy_file(...)
|
21
|
-
|
21
|
+
create_object_directory
|
22
22
|
version.copy_file(...)
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def copy_recursive(...)
|
26
|
+
create_object_directory
|
27
|
+
version.copy_recursive(...)
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_object_directory
|
26
31
|
FileUtils.mkdir_p(object_root)
|
27
32
|
end
|
28
33
|
|
@@ -7,13 +7,17 @@ module OCFL
|
|
7
7
|
# A new OCFL version
|
8
8
|
class DraftVersion
|
9
9
|
# @params [Directory] object_directory
|
10
|
-
def initialize(object_directory:)
|
10
|
+
def initialize(object_directory:, overwrite_head: false)
|
11
11
|
@object_directory = object_directory
|
12
12
|
@manifest = object_directory.inventory.manifest.dup
|
13
13
|
@state = {}
|
14
|
+
|
15
|
+
number = object_directory.head.delete_prefix("v").to_i
|
16
|
+
@version_number = "v#{overwrite_head ? number : number + 1}"
|
17
|
+
@prepared_content = @prepared = overwrite_head
|
14
18
|
end
|
15
19
|
|
16
|
-
attr_reader :object_directory, :manifest, :state
|
20
|
+
attr_reader :object_directory, :manifest, :state, :version_number
|
17
21
|
|
18
22
|
def move_file(incoming_path)
|
19
23
|
prepare_content_directory
|
@@ -27,19 +31,22 @@ module OCFL
|
|
27
31
|
FileUtils.cp(incoming_path, content_path)
|
28
32
|
end
|
29
33
|
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
# Copies files into the object and preserves their relative paths as logical directories in the object
|
35
|
+
def copy_recursive(incoming_path)
|
36
|
+
prepare_content_directory
|
37
|
+
incoming_path = incoming_path.delete_suffix("/")
|
38
|
+
Dir.glob("#{incoming_path}/**/*").reject { |fn| File.directory?(fn) }.each do |file|
|
39
|
+
logical_file_path = file.delete_prefix(incoming_path).delete_prefix("/")
|
40
|
+
add(file, logical_file_path:)
|
41
|
+
parent_dir = (content_path + logical_file_path).parent
|
42
|
+
FileUtils.mkdir_p(parent_dir)
|
43
|
+
FileUtils.cp(file, content_path + logical_file_path)
|
44
|
+
end
|
45
|
+
end
|
38
46
|
|
39
|
-
def add(incoming_path)
|
47
|
+
def add(incoming_path, logical_file_path: File.basename(incoming_path))
|
40
48
|
digest = Digest::SHA512.file(incoming_path).to_s
|
41
49
|
version_content_path = content_path.relative_path_from(object_directory.object_root)
|
42
|
-
logical_file_path = File.basename(incoming_path)
|
43
50
|
file_path_relative_to_root = (version_content_path + logical_file_path).to_s
|
44
51
|
@manifest[digest] = [file_path_relative_to_root]
|
45
52
|
@state[digest] = [logical_file_path]
|
@@ -68,14 +75,25 @@ module OCFL
|
|
68
75
|
object_directory.object_root + version_number
|
69
76
|
end
|
70
77
|
|
71
|
-
def version_number
|
72
|
-
@version_number ||= "v#{object_directory.head.delete_prefix("v").to_i + 1}"
|
73
|
-
end
|
74
|
-
|
75
78
|
def build_inventory
|
76
79
|
old_data = object_directory.inventory.data
|
77
|
-
versions = old_data.versions
|
78
|
-
|
80
|
+
versions = versions(old_data.versions)
|
81
|
+
# Prune items from manifest if they are not part of any version
|
82
|
+
|
83
|
+
Inventory::InventoryStruct.new(old_data.to_h.merge(manifest: filtered_manifest(versions),
|
84
|
+
head: version_number, versions:))
|
85
|
+
end
|
86
|
+
|
87
|
+
# This gives the update list of versions. The old list plus this new one.
|
88
|
+
# @param [Hash] old_versions the versions prior to this one.
|
89
|
+
def versions(old_versions)
|
90
|
+
old_versions.merge(version_number => Version.new(created: Time.now.utc.iso8601, state: @state))
|
91
|
+
end
|
92
|
+
|
93
|
+
# The manifest after unused SHAs have been filtered out.
|
94
|
+
def filtered_manifest(versions)
|
95
|
+
shas_in_versions = versions.values.flat_map { |v| v.state.keys }.uniq
|
96
|
+
manifest.slice(*shas_in_versions)
|
79
97
|
end
|
80
98
|
|
81
99
|
def save
|
data/lib/ocfl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocfl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|