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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e3f58e7b54e7d04913b3ab7ed778fe0c2fbfa01c9571ec7d5c62d9fb7ec9555
4
- data.tar.gz: 5b544b0a343c185571a2fccc1438bfd53426b7f6a02d4605b4d7a7f517058560
3
+ metadata.gz: 78897fbce0fd01688c27516dceba600ed7cd984668fd16abde32a1713c0ba40f
4
+ data.tar.gz: 3194d882e4b7f6cd347d652d5da38cb2fe02cfb18e36d84f50e012193a538a69
5
5
  SHA512:
6
- metadata.gz: e12c059af0471d6423fc0af754713d66f0d654d3196d331fc2d3a8a7d9f6642e8e7fada4749ad7fa2b7478cc64be4652b09aba2d1851d2d7f44100d1d52a6b14
7
- data.tar.gz: c0c2654d4261aad3f2e9db64b64338af9425e7aea73a92848a98561bf27ea3f0489a926857efc5e80990475b17b42a499657cad292e8b0e8d7593be647ab6d80
6
+ metadata.gz: ddc2f5ffe217717299f2e5d76313b2a124fabfbc7b1e1800db18ca36d2f79c716ef249c6fcb8a6a8bfd4e0c5bba3b8a30d6ae3498ef8fd0068d7df08985c72f5
7
+ data.tar.gz: 802bf935d2e911ce771e962d6faaf0821f682049424cf5ac893ec780b8fc89d22f844156a83dd38adbe045a31faa7e527b4d8406bcabe937bdf8a2e8afafcd93
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ro-crate (0.4.4)
4
+ ro-crate (0.4.5)
5
5
  addressable (~> 2.7.0)
6
6
  rubyzip (~> 2.0.0)
7
7
 
@@ -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
- list_all_files(source_directory).each do |rel_path|
77
- source_path = Pathname.new(::File.join(source_directory, rel_path)).expand_path
78
- if create_entities
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, io|
228
- entries[path] = io
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
- Dir.chdir(source_directory) { Dir.glob('**/*', ::File::FNM_DOTMATCH) }.reject do |path|
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ro-crate'
3
- s.version = '0.4.4'
3
+ s.version = '0.4.5'
4
4
  s.summary = 'Create, manipulate, read RO-Crates.'
5
5
  s.authors = ['Finn Bacall']
6
6
  s.email = 'finn.bacall@manchester.ac.uk'
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
- assert crate.entries['fish/root.txt']
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
- assert crate.entries['fish/data/nested.txt']
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ro-crate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn Bacall