ro-crate 0.5.0 → 0.5.1
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/data_entity.rb +41 -5
- data/lib/ro_crate/model/directory.rb +17 -12
- data/lib/ro_crate/model/file.rb +4 -25
- data/lib/ro_crate/model/remote_entry.rb +3 -2
- data/ro_crate.gemspec +1 -1
- data/test/fixtures/uri_heavy_crate/main.nf +2 -0
- data/test/fixtures/uri_heavy_crate/ro-crate-metadata.json +7071 -0
- data/test/fixtures/uri_heavy_crate/ro-crate-preview.html +3678 -0
- data/test/reader_test.rb +24 -0
- data/test/writer_test.rb +35 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28049e56f761e9b8684970817cc4eace0a60c78aee05b6a16688e589a2088357
|
4
|
+
data.tar.gz: 3e731b4c6039aa74ea34ab7d672fa665b99d4d030598a16ac593877cb0bf306f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac8be2df8a04041f7cafc51e04c2ee67d0e25599b1c7a16716aa0b61a4db132b5fb1e55a1bef48b7c6c83aea6bfaba1826a1ac294f58e3092a35438e1938433c
|
7
|
+
data.tar.gz: 13a3780ee9ff9c85ac6829b0f93e393df3917e9286468c54cd127d1fdba704d14ced069fafb7bcb76378c6b120c6598e431e905059983f1dcec704efefc038cf
|
data/Gemfile.lock
CHANGED
@@ -27,12 +27,25 @@ module ROCrate
|
|
27
27
|
# PLEASE NOTE, the new data entity will not be added to the crate. To do this, call Crate#add_data_entity.
|
28
28
|
#
|
29
29
|
# @param crate [Crate] The RO-Crate that owns this directory.
|
30
|
-
# @param source [nil]
|
31
|
-
#
|
32
|
-
#
|
30
|
+
# @param source [String, Pathname, ::File, URI, nil, #read] The source on the disk (or on the internet if a URI)
|
31
|
+
# where the content of this DataEntity can be found.
|
32
|
+
# @param crate_path [String, nil] The relative path within the RO-Crate where this data entity should be written.
|
33
|
+
# Also used as the ID of the DataEntity. Will be taken from `properties` or generated if `crate_path` is nil.
|
33
34
|
# @param properties [Hash{String => Object}] A hash of JSON-LD properties to associate with this DataEntity.
|
34
|
-
def initialize(crate, source = nil,
|
35
|
-
|
35
|
+
def initialize(crate, source = nil, crate_path = nil, properties = {})
|
36
|
+
if crate_path.is_a?(Hash) && properties.empty?
|
37
|
+
properties = crate_path
|
38
|
+
crate_path = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
@source = normalize_source(source)
|
42
|
+
|
43
|
+
if crate_path.nil?
|
44
|
+
crate_path = @source.basename.to_s if @source.respond_to?(:basename)
|
45
|
+
crate_path = @source.to_s if @source.is_a?(URI) && @source.absolute?
|
46
|
+
end
|
47
|
+
|
48
|
+
super(crate, crate_path, properties)
|
36
49
|
end
|
37
50
|
|
38
51
|
##
|
@@ -51,5 +64,28 @@ module ROCrate
|
|
51
64
|
def filepath
|
52
65
|
Addressable::URI.unescape(id.sub(/\A\//, '')).to_s # Remove initial / and decode %20 etc.
|
53
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
##
|
71
|
+
# Do some normalization of the given source. Coverts `::File` and `String` (if relative path) to `Pathname`
|
72
|
+
# and ensures they are expanded.
|
73
|
+
#
|
74
|
+
# @param source [String, Pathname, ::File, URI, nil, #read] The source on the disk (or on the internet if a URI).
|
75
|
+
# @return [Pathname, URI, nil, #read] An absolute Pathname or URI for the source.
|
76
|
+
def normalize_source(source)
|
77
|
+
if source.is_a?(String)
|
78
|
+
uri = URI(source) rescue nil
|
79
|
+
if uri&.absolute?
|
80
|
+
source = uri
|
81
|
+
else
|
82
|
+
source = Pathname.new(source)
|
83
|
+
end
|
84
|
+
elsif source.is_a?(::File)
|
85
|
+
source = Pathname.new(source)
|
86
|
+
end
|
87
|
+
|
88
|
+
source.is_a?(Pathname) ? source.expand_path : source
|
89
|
+
end
|
54
90
|
end
|
55
91
|
end
|
@@ -11,20 +11,21 @@ module ROCrate
|
|
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.
|
14
|
-
# @param
|
15
|
-
# @param crate_path [String] The relative path within the RO-Crate where this directory will be written.
|
14
|
+
# @param source [String, Pathname, ::File, nil] The source directory that will be included in the crate.
|
15
|
+
# @param crate_path [String, nil] The relative path within the RO-Crate where this directory will be written.
|
16
16
|
# @param properties [Hash{String => Object}] A hash of JSON-LD properties to associate with this directory.
|
17
|
-
def initialize(crate,
|
18
|
-
|
17
|
+
def initialize(crate, source = nil, crate_path = nil, properties = {})
|
18
|
+
super(crate, source, crate_path, properties)
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
|
20
|
+
@directory_entries = {}
|
21
|
+
if @source
|
22
|
+
if @source.is_a?(URI) && @source.absolute?
|
23
|
+
@entry = RemoteEntry.new(@source, directory: true)
|
24
|
+
else
|
25
|
+
@entry = Entry.new(@source)
|
26
|
+
populate_entries(@source)
|
27
|
+
end
|
25
28
|
end
|
26
|
-
|
27
|
-
super(crate, nil, crate_path, properties)
|
28
29
|
end
|
29
30
|
|
30
31
|
##
|
@@ -34,7 +35,7 @@ module ROCrate
|
|
34
35
|
# @return [Hash{String => Entry}>]
|
35
36
|
def payload
|
36
37
|
entries = {}
|
37
|
-
entries[filepath.chomp('/')] = @entry if @entry
|
38
|
+
entries[filepath.chomp('/')] = @entry if @entry && !remote?
|
38
39
|
|
39
40
|
@directory_entries.each do |rel_path, entry|
|
40
41
|
entries[full_entry_path(rel_path)] = entry
|
@@ -43,6 +44,10 @@ module ROCrate
|
|
43
44
|
entries
|
44
45
|
end
|
45
46
|
|
47
|
+
def remote?
|
48
|
+
@entry.remote?
|
49
|
+
end
|
50
|
+
|
46
51
|
private
|
47
52
|
|
48
53
|
##
|
data/lib/ro_crate/model/file.rb
CHANGED
@@ -15,33 +15,12 @@ module ROCrate
|
|
15
15
|
# @param crate_path [String] The relative path within the RO-Crate where this file will be written.
|
16
16
|
# @param properties [Hash{String => Object}] A hash of JSON-LD properties to associate with this file.
|
17
17
|
def initialize(crate, source, crate_path = nil, properties = {})
|
18
|
-
|
19
|
-
properties = crate_path
|
20
|
-
crate_path = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
if source.is_a?(String)
|
24
|
-
uri = URI(source) rescue nil
|
25
|
-
if uri.absolute?
|
26
|
-
source = uri
|
27
|
-
else
|
28
|
-
source = Pathname.new(source).expand_path
|
29
|
-
end
|
30
|
-
elsif source.is_a?(::File)
|
31
|
-
source = Pathname.new(source).expand_path
|
32
|
-
end
|
33
|
-
|
34
|
-
if crate_path.nil?
|
35
|
-
crate_path = source.basename.to_s if source.respond_to?(:basename)
|
36
|
-
crate_path = source.to_s if source.is_a?(URI) && source.absolute?
|
37
|
-
end
|
38
|
-
|
39
|
-
super(crate, nil, crate_path, properties)
|
18
|
+
super(crate, source, crate_path, properties)
|
40
19
|
|
41
|
-
if source.is_a?(URI) && source.absolute?
|
42
|
-
@entry = RemoteEntry.new(source)
|
20
|
+
if @source.is_a?(URI) && @source.absolute?
|
21
|
+
@entry = RemoteEntry.new(@source)
|
43
22
|
else
|
44
|
-
@entry = Entry.new(source)
|
23
|
+
@entry = Entry.new(@source)
|
45
24
|
end
|
46
25
|
end
|
47
26
|
|
@@ -9,8 +9,9 @@ module ROCrate
|
|
9
9
|
# Create a new RemoteEntry.
|
10
10
|
#
|
11
11
|
# @param uri [URI] An absolute URI.
|
12
|
-
def initialize(uri)
|
12
|
+
def initialize(uri, directory: false)
|
13
13
|
@uri = uri
|
14
|
+
@directory = directory
|
14
15
|
end
|
15
16
|
|
16
17
|
##
|
@@ -23,7 +24,7 @@ module ROCrate
|
|
23
24
|
##
|
24
25
|
# Does this RemoteEntry point to a directory
|
25
26
|
def directory?
|
26
|
-
|
27
|
+
@directory
|
27
28
|
end
|
28
29
|
|
29
30
|
##
|
data/ro_crate.gemspec
CHANGED