ro-crate 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ro_crate/model/crate.rb +10 -6
- data/lib/ro_crate/model/directory.rb +2 -2
- data/lib/ro_crate/model/file.rb +3 -1
- data/lib/ro_crate/reader.rb +1 -0
- data/ro_crate.gemspec +1 -1
- data/test/fixtures/sparse_directory_crate.zip +0 -0
- data/test/fixtures/sparse_directory_crate/fish/data/binary.jpg +0 -0
- data/test/fixtures/sparse_directory_crate/fish/data/info.txt +1 -0
- data/test/fixtures/sparse_directory_crate/fish/data/nested.txt +1 -0
- data/test/fixtures/sparse_directory_crate/fish/info.txt +1 -0
- data/test/fixtures/sparse_directory_crate/fish/root.txt +1 -0
- data/test/fixtures/sparse_directory_crate/listed_file.txt +1 -0
- data/test/fixtures/sparse_directory_crate/ro-crate-metadata.jsonld +32 -0
- data/test/fixtures/sparse_directory_crate/ro-crate-preview.html +66 -0
- data/test/fixtures/sparse_directory_crate/unlisted_file.txt +1 -0
- data/test/reader_test.rb +32 -0
- data/test/writer_test.rb +20 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4880110308b68d8bc35333b1fc8a8396ea30e36069f92e059b8c57ec3567d33e
|
4
|
+
data.tar.gz: 77a17a0436f2dea14254a3501f9db349eed5460851d94ab4e87adb7be83e1b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 711a45d7aaa63f8a5a7bba78e433d82875311472d6f4abfd6d388dd8565a7707036152c81de4059fd92da5b7851925caf9d808f39d115752e68eaddbdc85bac1
|
7
|
+
data.tar.gz: ce14efaf63e7224adc79cdb11d27bdec933be290ccf60196014cb7ce9380136451265a8f814e1ca7b70286fc32852024d429334bbaab18208d31095cd619dc9e
|
data/Gemfile.lock
CHANGED
data/lib/ro_crate/model/crate.rb
CHANGED
@@ -217,15 +217,19 @@ module ROCrate
|
|
217
217
|
|
218
218
|
alias_method :own_entries, :entries
|
219
219
|
##
|
220
|
-
#
|
221
|
-
# and the value is an Entry where the source data can be read.
|
220
|
+
# # The RO-Crate's "payload" of the crate - a map of all the files/directories contained in the RO-Crate, where the
|
221
|
+
# key is the destination path within the crate and the value is an Entry where the source data can be read.
|
222
222
|
#
|
223
223
|
# @return [Hash{String => Entry}>]
|
224
224
|
def entries
|
225
|
-
entries
|
226
|
-
|
227
|
-
|
228
|
-
|
225
|
+
# Gather a map of entries, starting from the crate itself, then any directory data entities, then finally any
|
226
|
+
# file data entities. This ensures in the case of a conflict, the more "specific" data entities take priority.
|
227
|
+
entries = own_entries
|
228
|
+
non_self_entities = default_entities.reject { |e| e == self }
|
229
|
+
sorted_entities = (non_self_entities | data_entities).sort_by { |e| e.is_a?(ROCrate::Directory) ? 0 : 1 }
|
230
|
+
|
231
|
+
sorted_entities.each do |entity|
|
232
|
+
entity.entries.each do |path, entry|
|
229
233
|
entries[path] = entry
|
230
234
|
end
|
231
235
|
end
|
@@ -30,8 +30,8 @@ module ROCrate
|
|
30
30
|
end
|
31
31
|
|
32
32
|
##
|
33
|
-
#
|
34
|
-
# and the value is an Entry where the source data can be read.
|
33
|
+
# The "payload" of this directory - a map of all the files/directories, where the key is the destination path
|
34
|
+
# within the crate and the value is an Entry where the source data can be read.
|
35
35
|
#
|
36
36
|
# @return [Hash{String => Entry}>]
|
37
37
|
def entries
|
data/lib/ro_crate/model/file.rb
CHANGED
@@ -52,7 +52,9 @@ module ROCrate
|
|
52
52
|
end
|
53
53
|
|
54
54
|
##
|
55
|
-
# A map
|
55
|
+
# The "payload". A map with a single key and value, of the relative filepath within the crate, to the source on disk
|
56
|
+
# where the actual bytes of the file can be read. Blank if remote.
|
57
|
+
#
|
56
58
|
# (for compatibility with Directory#entries)
|
57
59
|
#
|
58
60
|
# @return [Hash{String => Entry}>] The key is the location within the crate, and the value is an Entry.
|
data/lib/ro_crate/reader.rb
CHANGED
@@ -107,6 +107,7 @@ module ROCrate
|
|
107
107
|
crate.metadata.properties = entity_hash.delete(ROCrate::Metadata::IDENTIFIER)
|
108
108
|
preview_properties = entity_hash.delete(ROCrate::Preview::IDENTIFIER)
|
109
109
|
crate.preview.properties = preview_properties if preview_properties
|
110
|
+
crate.add_all(source, false)
|
110
111
|
extract_data_entities(crate, source, entity_hash).each do |entity|
|
111
112
|
crate.add_data_entity(entity)
|
112
113
|
end
|
data/ro_crate.gemspec
CHANGED
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
5678
|
@@ -0,0 +1 @@
|
|
1
|
+
I'm nested
|
@@ -0,0 +1 @@
|
|
1
|
+
1234
|
@@ -0,0 +1 @@
|
|
1
|
+
I'm at the root
|
@@ -0,0 +1 @@
|
|
1
|
+
123
|
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"@context": "https://w3id.org/ro/crate/1.0/context",
|
3
|
+
"@graph": [
|
4
|
+
{
|
5
|
+
"@id": "ro-crate-metadata.jsonld",
|
6
|
+
"@type": "CreativeWork",
|
7
|
+
"about": {
|
8
|
+
"@id": "./"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"@id": "ro-crate-preview.html",
|
13
|
+
"@type": "CreativeWork",
|
14
|
+
"about": {
|
15
|
+
"@id": "./"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"@id": "./",
|
20
|
+
"@type": "Dataset",
|
21
|
+
"hasPart": [
|
22
|
+
{
|
23
|
+
"@id": "listed_file.txt"
|
24
|
+
}
|
25
|
+
]
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"@id": "listed_file.txt",
|
29
|
+
"@type": "File"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>New RO-Crate</title>
|
5
|
+
<script type="application/ld+json">{
|
6
|
+
"@context": "https://w3id.org/ro/crate/1.1/context",
|
7
|
+
"@graph": [
|
8
|
+
{
|
9
|
+
"@id": "ro-crate-metadata.jsonld",
|
10
|
+
"@type": "CreativeWork",
|
11
|
+
"about": {
|
12
|
+
"@id": "./"
|
13
|
+
}
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"@id": "ro-crate-preview.html",
|
17
|
+
"@type": "CreativeWork",
|
18
|
+
"about": {
|
19
|
+
"@id": "./"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"@id": "./",
|
24
|
+
"@type": "Dataset",
|
25
|
+
"hasPart": [
|
26
|
+
{
|
27
|
+
"@id": "fish/"
|
28
|
+
}
|
29
|
+
]
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"@id": "fish/",
|
33
|
+
"@type": "Dataset"
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}</script>
|
37
|
+
<meta name="generator" content="https://github.com/fbacall/ro-crate-ruby">
|
38
|
+
<meta name="keywords" content="RO-Crate">
|
39
|
+
</head>
|
40
|
+
<body>
|
41
|
+
<h1>New RO-Crate</h1>
|
42
|
+
|
43
|
+
<p>
|
44
|
+
|
45
|
+
</p>
|
46
|
+
<dl>
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
</dl>
|
52
|
+
|
53
|
+
<h2>Contents</h2>
|
54
|
+
<ul>
|
55
|
+
|
56
|
+
<li id="__data_entity_fish/">
|
57
|
+
|
58
|
+
<strong>fish/</strong>
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
</li>
|
63
|
+
|
64
|
+
</ul>
|
65
|
+
</body>
|
66
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
456
|
data/test/reader_test.rb
CHANGED
@@ -163,4 +163,36 @@ class ReaderTest < Test::Unit::TestCase
|
|
163
163
|
assert_equal 'http://example.com/external_ref.txt', ext_file.id
|
164
164
|
assert_equal 'file contents', ext_file.source.read
|
165
165
|
end
|
166
|
+
|
167
|
+
test 'reading from directory with unlisted files' do
|
168
|
+
crate = ROCrate::Reader.read_directory(fixture_file('sparse_directory_crate').path)
|
169
|
+
|
170
|
+
assert_equal 11, crate.entries.count
|
171
|
+
assert crate.entries['listed_file.txt']
|
172
|
+
assert crate.entries['unlisted_file.txt']
|
173
|
+
assert crate.entries['fish']
|
174
|
+
assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
|
175
|
+
refute crate.entries['fish/root.txt'].directory?
|
176
|
+
assert crate.entries['fish/data'].directory?
|
177
|
+
assert crate.entries['fish/data/info.txt']
|
178
|
+
refute crate.entries['fish/data/nested.txt'].remote?
|
179
|
+
assert crate.entries['fish/data/binary.jpg']
|
180
|
+
assert_equal ['./', 'listed_file.txt', 'ro-crate-metadata.jsonld', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
|
181
|
+
end
|
182
|
+
|
183
|
+
test 'reading from a zip with unlisted files' do
|
184
|
+
crate = ROCrate::Reader.read_zip(fixture_file('sparse_directory_crate.zip').path)
|
185
|
+
|
186
|
+
assert_equal 11, crate.entries.count
|
187
|
+
assert crate.entries['listed_file.txt']
|
188
|
+
assert crate.entries['unlisted_file.txt']
|
189
|
+
assert crate.entries['fish']
|
190
|
+
assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
|
191
|
+
refute crate.entries['fish/root.txt'].directory?
|
192
|
+
assert crate.entries['fish/data'].directory?
|
193
|
+
assert crate.entries['fish/data/info.txt']
|
194
|
+
refute crate.entries['fish/data/nested.txt'].remote?
|
195
|
+
assert crate.entries['fish/data/binary.jpg']
|
196
|
+
assert_equal ['./', 'listed_file.txt', 'ro-crate-metadata.jsonld', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
|
197
|
+
end
|
166
198
|
end
|
data/test/writer_test.rb
CHANGED
@@ -112,4 +112,24 @@ class WriterTest < Test::Unit::TestCase
|
|
112
112
|
assert_equal 2529, ::File.size(::File.join(dir, 'data', 'binary.jpg'))
|
113
113
|
end
|
114
114
|
end
|
115
|
+
|
116
|
+
test 'reading and writing out a directory crate produces an identical crate' do
|
117
|
+
fixture = fixture_file('sparse_directory_crate').path
|
118
|
+
Dir.mktmpdir do |dir|
|
119
|
+
dir = ::File.join(dir, 'new_directory')
|
120
|
+
crate = ROCrate::Reader.read(fixture)
|
121
|
+
|
122
|
+
ROCrate::Writer.new(crate).write(dir)
|
123
|
+
expected_files = Dir.chdir(fixture) { Dir.glob('**/*') }
|
124
|
+
actual_files = Dir.chdir(dir) { Dir.glob('**/*') }
|
125
|
+
assert_equal expected_files, actual_files
|
126
|
+
expected_files.each do |file|
|
127
|
+
next if file == 'ro-crate-metadata.jsonld' # Expected context gets updated.
|
128
|
+
next if file == 'ro-crate-preview.html' # RO-Crate preview format changed
|
129
|
+
abs_file_path = ::File.join(fixture, file)
|
130
|
+
next if ::File.directory?(abs_file_path)
|
131
|
+
assert_equal ::File.read(abs_file_path), ::File.read(::File.join(dir, file)), "#{file} didn't match"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
115
135
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ro-crate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Finn Bacall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -167,6 +167,16 @@ files:
|
|
167
167
|
- test/fixtures/info.txt
|
168
168
|
- test/fixtures/spaces/file with spaces.txt
|
169
169
|
- test/fixtures/spaces/ro-crate-metadata.jsonld
|
170
|
+
- test/fixtures/sparse_directory_crate.zip
|
171
|
+
- test/fixtures/sparse_directory_crate/fish/data/binary.jpg
|
172
|
+
- test/fixtures/sparse_directory_crate/fish/data/info.txt
|
173
|
+
- test/fixtures/sparse_directory_crate/fish/data/nested.txt
|
174
|
+
- test/fixtures/sparse_directory_crate/fish/info.txt
|
175
|
+
- test/fixtures/sparse_directory_crate/fish/root.txt
|
176
|
+
- test/fixtures/sparse_directory_crate/listed_file.txt
|
177
|
+
- test/fixtures/sparse_directory_crate/ro-crate-metadata.jsonld
|
178
|
+
- test/fixtures/sparse_directory_crate/ro-crate-preview.html
|
179
|
+
- test/fixtures/sparse_directory_crate/unlisted_file.txt
|
170
180
|
- test/fixtures/workflow-0.2.0.zip
|
171
181
|
- test/fixtures/workflow-0.2.0/Dockerfile
|
172
182
|
- test/fixtures/workflow-0.2.0/README.md
|