ro-crate 0.4.13 → 0.4.14

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: 364757350da7d275b02def348bfd97782ad0ae31728c44f0691bc084e4d94ac9
4
- data.tar.gz: 6b56ae58b682a4618dcb92ca78cbae720426316bc8ec50b9377fb9fda8ec9137
3
+ metadata.gz: 5d94d65b4375c3923a828f763c749e9958d975c2f3fd3ee55b996f718cd9317c
4
+ data.tar.gz: 3ce5e362db42e5a790991bef4fe252d507a35e83eff00a58b1fe99ce4f5808e6
5
5
  SHA512:
6
- metadata.gz: a2b14f9c64528476a18f84d0292311484e975a3dc6085c00c94f5dac8d84fa144e91bb6138c876db4a4079aeec4222eb6a1f91458e2ef0260defa9d3a0a42d57
7
- data.tar.gz: b56d257868b7cb94f341e844223d14988c280fff34bb54dd1a676d47681d96afc8193ebb60a22eecfef7e96dc0d2ce03ed1571190a1717fbe56d1b80ed579053
6
+ metadata.gz: dd26c3d0fc2783f7424ba022ae03d5cc14c0e4aa7f96e2c6b682f82be3af9cee5cacb1480b414b5ab2f37d08e19b38b377455afd1ec74017901788a4a6500bab
7
+ data.tar.gz: eb6f983303b2b50fafaec3a03c4c3f855b4c12a4fcd80611d20916ec1f64c078973e842d1425c3101a1609b16db3bdfbe56eccde2a703de0efc360df0a48550f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ro-crate (0.4.13)
4
+ ro-crate (0.4.14)
5
5
  addressable (>= 2.7, < 2.9)
6
6
  rubyzip (~> 2.0.0)
7
7
 
@@ -5,10 +5,6 @@ module ROCrate
5
5
  class DataEntity < Entity
6
6
  properties(%w[name contentSize dateModified encodingFormat identifier sameAs author])
7
7
 
8
- def self.format_local_id(id)
9
- super.chomp('/')
10
- end
11
-
12
8
  ##
13
9
  # Return an appropriate specialization of DataEntity for the given properties.
14
10
  # @param props [Hash] Set of properties to try and infer the type from.
@@ -18,11 +14,27 @@ module ROCrate
18
14
  type = [type] unless type.is_a?(Array)
19
15
  if type.include?('Dataset')
20
16
  ROCrate::Directory
21
- else
17
+ elsif type.include?('File')
22
18
  ROCrate::File
19
+ else
20
+ self
23
21
  end
24
22
  end
25
23
 
24
+ ##
25
+ # Create a new ROCrate::DataEntity. This entity represents something that is neither a file or directory, but
26
+ # still constitutes part of the crate.
27
+ # PLEASE NOTE, the new data entity will not be added to the crate. To do this, call Crate#add_data_entity.
28
+ #
29
+ # @param crate [Crate] The RO-Crate that owns this directory.
30
+ # @param source [nil] Ignored. For compatibility with the File and Directory constructor signatures.
31
+ # @param id [String, nil] An ID to identify this DataEntity, or nil to auto-generate an appropriate one,
32
+ # (or determine via the properties param)
33
+ # @param properties [Hash{String => Object}] A hash of JSON-LD properties to associate with this DataEntity.
34
+ def initialize(crate, source = nil, id = nil, properties = {})
35
+ super(crate, id, properties)
36
+ end
37
+
26
38
  ##
27
39
  # The payload of all the files/directories associated with this DataEntity, mapped by their relative file path.
28
40
  #
@@ -3,11 +3,11 @@ module ROCrate
3
3
  # A data entity that represents a directory of potentially many files and subdirectories (or none).
4
4
  class Directory < DataEntity
5
5
  def self.format_local_id(id)
6
- super + '/'
6
+ super.chomp('/') + '/'
7
7
  end
8
8
 
9
9
  ##
10
- # Create a new Directory. PLEASE NOTE, the new directory will not be added to the crate. To do this, call
10
+ # Create a new ROCrate::Directory. PLEASE NOTE, the new directory will not be added to the crate. To do this, call
11
11
  # Crate#add_data_entity, or just use Crate#add_directory.
12
12
  #
13
13
  # @param crate [Crate] The RO-Crate that owns this directory.
@@ -24,7 +24,7 @@ module ROCrate
24
24
  crate_path = source_directory.basename.to_s if crate_path.nil?
25
25
  end
26
26
 
27
- super(crate, crate_path, properties)
27
+ super(crate, nil, crate_path, properties)
28
28
  end
29
29
 
30
30
  ##
@@ -2,6 +2,10 @@ module ROCrate
2
2
  ##
3
3
  # A data entity that represents a single file.
4
4
  class File < DataEntity
5
+ def self.format_local_id(id)
6
+ super.chomp('/')
7
+ end
8
+
5
9
  ##
6
10
  # Create a new ROCrate::File. PLEASE NOTE, the new file will not be added to the crate. To do this, call
7
11
  # Crate#add_data_entity, or just use Crate#add_file.
@@ -32,7 +36,7 @@ module ROCrate
32
36
  crate_path = source.to_s if source.is_a?(URI) && source.absolute?
33
37
  end
34
38
 
35
- super(crate, crate_path, properties)
39
+ super(crate, nil, crate_path, properties)
36
40
 
37
41
  if source.is_a?(URI) && source.absolute?
38
42
  @entry = RemoteEntry.new(source)
@@ -245,10 +245,10 @@ module ROCrate
245
245
  fullpath = ::File.join(source, i)
246
246
  path = Pathname.new(fullpath) if ::File.exist?(fullpath)
247
247
  end
248
- unless path
249
- warn "Missing file/directory: #{id}, skipping..."
250
- return nil
251
- end
248
+ # unless path
249
+ # warn "Missing file/directory: #{id}, skipping..."
250
+ # return nil
251
+ # end
252
252
  end
253
253
 
254
254
  entity_class.new(crate, path, decoded_id, entity_props)
@@ -262,7 +262,9 @@ module ROCrate
262
262
  # mapped by its @id, or nil if nothing is found.
263
263
  def self.extract_metadata_entity(entities)
264
264
  key = entities.detect do |_, props|
265
- props.dig('conformsTo', '@id')&.start_with?(ROCrate::Metadata::RO_CRATE_BASE)
265
+ conforms = props['conformsTo']
266
+ conforms = [conforms] unless conforms.is_a?(Array)
267
+ conforms.compact.any? { |c| c['@id']&.start_with?(ROCrate::Metadata::RO_CRATE_BASE) }
266
268
  end&.first
267
269
 
268
270
  return entities.delete(key) if key
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.13'
3
+ s.version = '0.4.14'
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/entity_test.rb CHANGED
@@ -38,11 +38,11 @@ class EntityTest < Test::Unit::TestCase
38
38
  test 'fetch appropriate class for type' do
39
39
  assert_equal ROCrate::File, ROCrate::DataEntity.specialize({ '@type' => 'File' })
40
40
  assert_equal ROCrate::File, ROCrate::DataEntity.specialize({ '@type' => ['File', 'Image'] })
41
- assert_equal ROCrate::File, ROCrate::DataEntity.specialize({ '@type' => 'SoftwareSourceCode' })
42
- assert_equal ROCrate::File, ROCrate::DataEntity.specialize({ '@type' => 'anything that isnt a directory' })
41
+ assert_equal ROCrate::DataEntity, ROCrate::DataEntity.specialize({ '@type' => 'SoftwareSourceCode' })
42
+ assert_equal ROCrate::DataEntity, ROCrate::DataEntity.specialize({ '@type' => 'anything that isnt a directory' })
43
43
  assert_equal ROCrate::Directory, ROCrate::DataEntity.specialize({ '@type' => 'Dataset' })
44
44
  assert_equal ROCrate::Directory, ROCrate::DataEntity.specialize({ '@type' => ['Dataset', 'Image'] })
45
- assert_equal ROCrate::File, ROCrate::DataEntity.specialize({ '@type' => 'Person' })
45
+ assert_equal ROCrate::DataEntity, ROCrate::DataEntity.specialize({ '@type' => 'Person' })
46
46
  assert_equal ROCrate::File, ROCrate::DataEntity.specialize({ '@type' => ['File', 'Image'], '@id' => 'http://www.external.com' })
47
47
 
48
48
  assert_equal ROCrate::Person, ROCrate::ContextualEntity.specialize({ '@type' => 'Person' })
@@ -0,0 +1,33 @@
1
+ {
2
+ "@context": [
3
+ "https://w3id.org/ro/crate/1.1/context",
4
+ {
5
+ "@vocab": "http://schema.org/"
6
+ },
7
+ {
8
+ "@base": null
9
+ }
10
+ ],
11
+ "@graph": [
12
+ {
13
+ "@id": "#collection",
14
+ "@type": "RepositoryCollection",
15
+ "name": "Test collection"
16
+ },
17
+ {
18
+ "@id": "./",
19
+ "@type": "Dataset",
20
+ "hasFile": [],
21
+ "hasPart": [{"@id": "#collection"}],
22
+ "name": "testing hasPart"
23
+ },
24
+ {
25
+ "@id": "ro-crate-metadata.json",
26
+ "@type": "CreativeWork",
27
+ "about": {
28
+ "@id": "./"
29
+ },
30
+ "identifier": "ro-crate-metadata.json"
31
+ }
32
+ ]
33
+ }
@@ -24,9 +24,10 @@
24
24
  "about": {
25
25
  "@id": "./"
26
26
  },
27
- "conformsTo": {
28
- "@id": "https://w3id.org/ro/crate/1.1"
29
- }
27
+ "conformsTo": [
28
+ { "@id": "https://w3id.org/ro/crate/1.1" },
29
+ { "@id": "https://about.workflowhub.eu/Workflow-RO-Crate/" }
30
+ ]
30
31
  },
31
32
  {
32
33
  "@id": "./",
@@ -128,6 +129,12 @@
128
129
  "@type": "SoftwareApplication",
129
130
  "name": "Planemo",
130
131
  "url": {"@id": "https://github.com/galaxyproject/planemo"}
132
+ },
133
+ {
134
+ "@id": "https://about.workflowhub.eu/Workflow-RO-Crate/",
135
+ "@type": "CreativeWork",
136
+ "name": "Workflow RO-Crate Profile",
137
+ "version": "0.2.0"
131
138
  }
132
139
  ]
133
140
  }
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "@id": "workflow/workflow.knime",
126
- "@type": "SoftwareSourceCode",
126
+ "@type": ["File", "SoftwareSourceCode"],
127
127
  "additionalType": {
128
128
  "@id": "wfdesc:Workflow"
129
129
  },
@@ -161,7 +161,7 @@
161
161
  },
162
162
  {
163
163
  "@id": "tools/RetroPath2.cwl",
164
- "@type": "SoftwareSourceCode",
164
+ "@type": ["File", "SoftwareSourceCode"],
165
165
  "additionalType": {
166
166
  "@id": "wfdesc:Workflow"
167
167
  },
@@ -188,7 +188,7 @@
188
188
  },
189
189
  {
190
190
  "@id": "workflow/workflow.svg",
191
- "@type": "ImageObject",
191
+ "@type": ["File", "ImageObject"],
192
192
  "additionalType": {"@id": "roterms:Sketch"},
193
193
  "encodingFormat": "image/svg+xml",
194
194
  "description": "Diagram of RetroPath2.0 workflow",
@@ -201,7 +201,7 @@
201
201
  },
202
202
  {
203
203
  "@id": "Dockerfile",
204
- "@type": "SoftwareSourceCode",
204
+ "@type": ["File", "SoftwareSourceCode"],
205
205
  "url": {
206
206
  "@id": "https://hub.docker.com/r/ibisba/retropath2/"
207
207
  },
@@ -220,7 +220,7 @@
220
220
  },
221
221
  {
222
222
  "@id": "test/test.sh",
223
- "@type": "SoftwareSourceCode",
223
+ "@type": ["File", "SoftwareSourceCode"],
224
224
  "additionalType": {
225
225
  "@id": "wf4ever:Script"
226
226
  },
Binary file
data/test/reader_test.rb CHANGED
@@ -4,12 +4,13 @@ class ReaderTest < Test::Unit::TestCase
4
4
  test 'reading from directory' do
5
5
  crate = ROCrate::Reader.read(fixture_file('workflow-0.2.0').path)
6
6
 
7
- refute crate.dereference('.ssh/id_rsa')
7
+ refute crate.dereference('~/.ssh/id_rsa')
8
8
 
9
9
  entity = crate.dereference('workflow/workflow.knime')
10
10
  assert_not_nil entity
11
11
  assert entity.is_a?(ROCrate::File)
12
- assert_equal 'SoftwareSourceCode', entity.type
12
+ assert entity.has_type?('SoftwareSourceCode')
13
+ assert entity.has_type?('File')
13
14
 
14
15
  entity = crate.dereference('workflow/')
15
16
  assert_not_nil entity
@@ -19,22 +20,26 @@ class ReaderTest < Test::Unit::TestCase
19
20
  entity = crate.dereference('tools/RetroPath2.cwl')
20
21
  assert_not_nil entity
21
22
  assert entity.is_a?(ROCrate::File)
22
- assert_equal 'SoftwareSourceCode', entity.type
23
+ assert entity.has_type?('SoftwareSourceCode')
24
+ assert entity.has_type?('File')
23
25
 
24
26
  entity = crate.dereference('workflow/workflow.svg')
25
27
  assert_not_nil entity
26
28
  assert entity.is_a?(ROCrate::File)
27
- assert_equal 'ImageObject', entity.type
29
+ assert entity.has_type?('ImageObject')
30
+ assert entity.has_type?('File')
28
31
 
29
32
  entity = crate.dereference('Dockerfile')
30
33
  assert_not_nil entity
31
34
  assert entity.is_a?(ROCrate::File)
32
- assert_equal 'SoftwareSourceCode', entity.type
35
+ assert entity.has_type?('SoftwareSourceCode')
36
+ assert entity.has_type?('File')
33
37
 
34
38
  entity = crate.dereference('test/test.sh')
35
39
  assert_not_nil entity
36
40
  assert entity.is_a?(ROCrate::File)
37
- assert_equal 'SoftwareSourceCode', entity.type
41
+ assert entity.has_type?('SoftwareSourceCode')
42
+ assert entity.has_type?('File')
38
43
 
39
44
  # Example is broken
40
45
  # entity = crate.dereference('README.md')
@@ -46,12 +51,13 @@ class ReaderTest < Test::Unit::TestCase
46
51
  test 'reading from zip' do
47
52
  crate = ROCrate::Reader.read(fixture_file('workflow-0.2.0.zip'))
48
53
 
49
- refute crate.dereference('.ssh/id_rsa')
54
+ refute crate.dereference('~/.ssh/id_rsa')
50
55
 
51
56
  entity = crate.dereference('workflow/workflow.knime')
52
57
  assert_not_nil entity
53
58
  assert entity.is_a?(ROCrate::File)
54
- assert_equal 'SoftwareSourceCode', entity.type
59
+ assert entity.has_type?('SoftwareSourceCode')
60
+ assert entity.has_type?('File')
55
61
 
56
62
  entity = crate.dereference('workflow/')
57
63
  assert_not_nil entity
@@ -61,22 +67,26 @@ class ReaderTest < Test::Unit::TestCase
61
67
  entity = crate.dereference('tools/RetroPath2.cwl')
62
68
  assert_not_nil entity
63
69
  assert entity.is_a?(ROCrate::File)
64
- assert_equal 'SoftwareSourceCode', entity.type
70
+ assert entity.has_type?('SoftwareSourceCode')
71
+ assert entity.has_type?('File')
65
72
 
66
73
  entity = crate.dereference('workflow/workflow.svg')
67
74
  assert_not_nil entity
68
75
  assert entity.is_a?(ROCrate::File)
69
- assert_equal 'ImageObject', entity.type
76
+ assert entity.has_type?('ImageObject')
77
+ assert entity.has_type?('File')
70
78
 
71
79
  entity = crate.dereference('Dockerfile')
72
80
  assert_not_nil entity
73
81
  assert entity.is_a?(ROCrate::File)
74
- assert_equal 'SoftwareSourceCode', entity.type
82
+ assert entity.has_type?('SoftwareSourceCode')
83
+ assert entity.has_type?('File')
75
84
 
76
85
  entity = crate.dereference('test/test.sh')
77
86
  assert_not_nil entity
78
87
  assert entity.is_a?(ROCrate::File)
79
- assert_equal 'SoftwareSourceCode', entity.type
88
+ assert entity.has_type?('SoftwareSourceCode')
89
+ assert entity.has_type?('File')
80
90
 
81
91
  # Example is broken
82
92
  # entity = crate.dereference('README.md')
@@ -258,4 +268,15 @@ class ReaderTest < Test::Unit::TestCase
258
268
  assert crate.preview.source.source.is_a?(Pathname)
259
269
  assert_equal 80526, crate.preview.source.read.length
260
270
  end
271
+
272
+ test 'read crate with data entity that is neither file or directory' do
273
+ crate = ROCrate::Reader.read_directory(fixture_file('misc_data_entity_crate').path)
274
+
275
+ entity = crate.get('#collection')
276
+ assert entity.is_a?(ROCrate::DataEntity)
277
+ refute entity.is_a?(ROCrate::File)
278
+ refute entity.is_a?(ROCrate::Directory)
279
+ assert entity.has_type?('RepositoryCollection')
280
+ assert entity.payload.empty?
281
+ end
261
282
  end
data/test/writer_test.rb CHANGED
@@ -189,4 +189,15 @@ class WriterTest < Test::Unit::TestCase
189
189
  assert ::File.exist?(::File.join(dir, 'data', 'binary.jpg'))
190
190
  end
191
191
  end
192
+
193
+ test 'write crate with data entity that is neither file or directory' do
194
+ crate = ROCrate::Reader.read_directory(fixture_file('misc_data_entity_crate').path)
195
+ Dir.mktmpdir do |dir|
196
+ ROCrate::Writer.new(crate).write(dir)
197
+ Dir.chdir(dir) do
198
+ file_list = Dir.glob('*').sort
199
+ assert_equal ["ro-crate-metadata.json", "ro-crate-preview.html"], file_list
200
+ end
201
+ end
202
+ end
192
203
  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.13
4
+ version: 0.4.14
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-09-29 00:00:00.000000000 Z
11
+ date: 2021-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -175,6 +175,7 @@ files:
175
175
  - test/fixtures/directory_crate/ro-crate-preview.html
176
176
  - test/fixtures/file with spaces.txt
177
177
  - test/fixtures/info.txt
178
+ - test/fixtures/misc_data_entity_crate/ro-crate-metadata.json
178
179
  - test/fixtures/nested_directory.zip
179
180
  - test/fixtures/ro-crate-galaxy-sortchangecase/LICENSE
180
181
  - test/fixtures/ro-crate-galaxy-sortchangecase/README.md