ro-crate 0.4.4 → 0.4.5
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 +9 -8
- data/lib/ro_crate/model/directory.rb +8 -5
- data/ro_crate.gemspec +1 -1
- data/test/crate_test.rb +34 -2
- data/test/reader_test.rb +4 -2
- 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: 78897fbce0fd01688c27516dceba600ed7cd984668fd16abde32a1713c0ba40f
|
4
|
+
data.tar.gz: 3194d882e4b7f6cd347d652d5da38cb2fe02cfb18e36d84f50e012193a538a69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddc2f5ffe217717299f2e5d76313b2a124fabfbc7b1e1800db18ca36d2f79c716ef249c6fcb8a6a8bfd4e0c5bba3b8a30d6ae3498ef8fd0068d7df08985c72f5
|
7
|
+
data.tar.gz: 802bf935d2e911ce771e962d6faaf0821f682049424cf5ac893ec780b8fc89d22f844156a83dd38adbe045a31faa7e527b4d8406bcabe937bdf8a2e8afafcd93
|
data/Gemfile.lock
CHANGED
data/lib/ro_crate/model/crate.rb
CHANGED
@@ -68,22 +68,23 @@ module ROCrate
|
|
68
68
|
#
|
69
69
|
# @param source_directory [String, Pathname, ::File,] The source directory that will be included in the crate.
|
70
70
|
# @param create_entities [Boolean] Whether to create data entities for the added content, or just include them anonymously.
|
71
|
+
# @param include_hidden [Boolean] Whether to include hidden files, i.e. those prefixed by a `.` (period).
|
71
72
|
#
|
72
73
|
# @return [Array<DataEntity>] Any entities that were created from the directory contents. Will be empty if `create_entities` was false.
|
73
|
-
def add_all(source_directory, create_entities = true)
|
74
|
+
def add_all(source_directory, create_entities = true, include_hidden: false)
|
74
75
|
added = []
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
if create_entities
|
78
|
+
list_all_files(source_directory, include_hidden: include_hidden).each do |rel_path|
|
79
|
+
source_path = Pathname.new(::File.join(source_directory, rel_path)).expand_path
|
79
80
|
if source_path.directory?
|
80
81
|
added << add_directory(source_path, rel_path)
|
81
82
|
else
|
82
83
|
added << add_file(source_path, rel_path)
|
83
84
|
end
|
84
|
-
else
|
85
|
-
populate_entries(Pathname.new(::File.expand_path(source_directory)))
|
86
85
|
end
|
86
|
+
else
|
87
|
+
populate_entries(Pathname.new(::File.expand_path(source_directory)), include_hidden: include_hidden)
|
87
88
|
end
|
88
89
|
|
89
90
|
added
|
@@ -224,8 +225,8 @@ module ROCrate
|
|
224
225
|
entries = {}
|
225
226
|
|
226
227
|
(default_entities | data_entities).each do |entity|
|
227
|
-
(entity == self ? own_entries : entity.entries).each do |path,
|
228
|
-
entries[path] =
|
228
|
+
(entity == self ? own_entries : entity.entries).each do |path, entry|
|
229
|
+
entries[path] = entry
|
229
230
|
end
|
230
231
|
end
|
231
232
|
|
@@ -21,7 +21,7 @@ module ROCrate
|
|
21
21
|
|
22
22
|
if source_directory
|
23
23
|
source_directory = Pathname.new(::File.expand_path(source_directory))
|
24
|
-
@entry = source_directory
|
24
|
+
@entry = Entry.new(source_directory)
|
25
25
|
populate_entries(source_directory)
|
26
26
|
crate_path = source_directory.basename.to_s if crate_path.nil?
|
27
27
|
end
|
@@ -51,13 +51,14 @@ module ROCrate
|
|
51
51
|
# Populate this directory with files/directories from a given source directory on disk.
|
52
52
|
#
|
53
53
|
# @param source_directory [Pathname] The source directory to populate from.
|
54
|
+
# @param include_hidden [Boolean] Whether to include hidden files, i.e. those prefixed by a `.` (period).
|
54
55
|
#
|
55
56
|
# @return [Hash{String => Entry}>] The files/directories that were populated.
|
56
57
|
# The key is the relative path of the file/directory, and the value is an Entry object where data can be read etc.
|
57
|
-
def populate_entries(source_directory)
|
58
|
+
def populate_entries(source_directory, include_hidden: false)
|
58
59
|
raise 'Not a directory' unless ::File.directory?(source_directory)
|
59
60
|
@directory_entries = {}
|
60
|
-
list_all_files(source_directory).each do |rel_path|
|
61
|
+
list_all_files(source_directory, include_hidden: include_hidden).each do |rel_path|
|
61
62
|
source_path = Pathname.new(::File.join(source_directory, rel_path)).expand_path
|
62
63
|
@directory_entries[rel_path] = Entry.new(source_path)
|
63
64
|
end
|
@@ -69,8 +70,10 @@ module ROCrate
|
|
69
70
|
::File.join(filepath, relative_path)
|
70
71
|
end
|
71
72
|
|
72
|
-
def list_all_files(source_directory)
|
73
|
-
|
73
|
+
def list_all_files(source_directory, include_hidden: false)
|
74
|
+
args = ['**/*']
|
75
|
+
args << ::File::FNM_DOTMATCH if include_hidden
|
76
|
+
Dir.chdir(source_directory) { Dir.glob(*args) }.reject do |path|
|
74
77
|
path == '.' || path == '..' || path.end_with?('/.')
|
75
78
|
end
|
76
79
|
end
|
data/ro_crate.gemspec
CHANGED
data/test/crate_test.rb
CHANGED
@@ -201,7 +201,7 @@ class CrateTest < Test::Unit::TestCase
|
|
201
201
|
|
202
202
|
test 'can add an entire directory tree as data entities' do
|
203
203
|
crate = ROCrate::Crate.new
|
204
|
-
entities = crate.add_all(fixture_file('directory').path)
|
204
|
+
entities = crate.add_all(fixture_file('directory').path, include_hidden: true)
|
205
205
|
|
206
206
|
paths = crate.entries.keys
|
207
207
|
assert_equal 11, paths.length
|
@@ -234,7 +234,7 @@ class CrateTest < Test::Unit::TestCase
|
|
234
234
|
|
235
235
|
test 'can create an RO-Crate using content from a given directory' do
|
236
236
|
crate = ROCrate::Crate.new
|
237
|
-
entities = crate.add_all(fixture_file('directory').path, false)
|
237
|
+
entities = crate.add_all(fixture_file('directory').path, false, include_hidden: true)
|
238
238
|
|
239
239
|
assert_empty entities
|
240
240
|
|
@@ -261,4 +261,36 @@ class CrateTest < Test::Unit::TestCase
|
|
261
261
|
assert_nil crate.dereference('data/nested.txt')
|
262
262
|
assert_nil crate.dereference('.dotfile')
|
263
263
|
end
|
264
|
+
|
265
|
+
test 'can create an RO-Crate using content from a given directory, excluding hidden files' do
|
266
|
+
crate = ROCrate::Crate.new
|
267
|
+
entities = crate.add_all(fixture_file('directory').path)
|
268
|
+
|
269
|
+
paths = crate.entries.keys
|
270
|
+
assert_equal 8, paths.length
|
271
|
+
assert_includes paths, 'data'
|
272
|
+
assert_includes paths, 'root.txt'
|
273
|
+
assert_includes paths, 'info.txt'
|
274
|
+
assert_includes paths, 'data/binary.jpg'
|
275
|
+
assert_includes paths, 'data/info.txt'
|
276
|
+
assert_includes paths, 'data/nested.txt'
|
277
|
+
assert_not_includes paths, '.dotfile'
|
278
|
+
assert_not_includes paths, '.dir'
|
279
|
+
assert_not_includes paths, '.dir/test.txt'
|
280
|
+
assert_includes paths, 'ro-crate-metadata.json'
|
281
|
+
assert_includes paths, 'ro-crate-preview.html'
|
282
|
+
|
283
|
+
assert_equal 6, entities.length
|
284
|
+
assert_equal 'ROCrate::Directory', crate.dereference('data/').class.name
|
285
|
+
assert_equal 'ROCrate::File', crate.dereference('root.txt').class.name
|
286
|
+
assert_equal 'ROCrate::File', crate.dereference('info.txt').class.name
|
287
|
+
assert_equal 'ROCrate::File', crate.dereference('data/binary.jpg').class.name
|
288
|
+
assert_equal 'ROCrate::File', crate.dereference('data/info.txt').class.name
|
289
|
+
assert_equal 'ROCrate::File', crate.dereference('data/nested.txt').class.name
|
290
|
+
assert_nil crate.dereference('.dotfile')
|
291
|
+
assert_nil crate.dereference('.dir/')
|
292
|
+
assert_nil crate.dereference('.dir/test.txt')
|
293
|
+
|
294
|
+
assert_equal "5678\n", crate.dereference('data/info.txt').source.read
|
295
|
+
end
|
264
296
|
end
|
data/test/reader_test.rb
CHANGED
@@ -109,11 +109,13 @@ class ReaderTest < Test::Unit::TestCase
|
|
109
109
|
test 'reading from directory with directories' do
|
110
110
|
crate = ROCrate::Reader.read_directory(fixture_file('directory_crate').path)
|
111
111
|
|
112
|
+
assert crate.entries.values.all? { |e| e.is_a?(ROCrate::Entry) }
|
112
113
|
assert crate.entries['fish/info.txt']
|
113
114
|
assert_equal '1234', crate.entries['fish/info.txt'].source.read.chomp
|
114
|
-
|
115
|
+
refute crate.entries['fish/root.txt'].directory?
|
116
|
+
assert crate.entries['fish/data'].directory?
|
115
117
|
assert crate.entries['fish/data/info.txt']
|
116
|
-
|
118
|
+
refute crate.entries['fish/data/nested.txt'].remote?
|
117
119
|
assert crate.entries['fish/data/binary.jpg']
|
118
120
|
assert_equal ['./', 'fish/', 'ro-crate-metadata.jsonld', 'ro-crate-preview.html'], crate.entities.map(&:id).sort
|
119
121
|
end
|