ro-bundle 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.ruby-gemset +0 -1
- data/.ruby-version +1 -2
- data/.travis.yml +9 -1
- data/Licence.rdoc +1 -1
- data/ReadMe.rdoc +8 -7
- data/bin/dir2ro +3 -2
- data/bin/ro-bundle-info +2 -2
- data/bin/verify-ro-bundle +2 -2
- data/bin/zip2ro +2 -2
- data/lib/ro-bundle.rb +3 -2
- data/lib/ro-bundle/exceptions.rb +0 -14
- data/lib/ro-bundle/file.rb +28 -20
- data/lib/ro-bundle/ro/agent.rb +1 -1
- data/lib/ro-bundle/ro/aggregate.rb +46 -38
- data/lib/ro-bundle/ro/annotation.rb +58 -20
- data/lib/ro-bundle/ro/manifest-entry.rb +52 -0
- data/lib/ro-bundle/ro/manifest.rb +76 -38
- data/lib/ro-bundle/ro/provenance.rb +78 -11
- data/lib/ro-bundle/ro/proxy.rb +80 -0
- data/lib/ro-bundle/util.rb +1 -1
- data/lib/ro-bundle/version.rb +1 -1
- data/ro-bundle.gemspec +6 -5
- data/test/data/HelloAnyone.robundle +0 -0
- data/test/data/example3-manifest.json +7 -7
- data/test/data/example6-manifest.json +17 -0
- data/test/helpers/fake_provenance.rb +4 -1
- data/test/tc_add_annotation.rb +47 -44
- data/test/tc_aggregate.rb +70 -65
- data/test/tc_annotation.rb +70 -11
- data/test/tc_create.rb +30 -12
- data/test/tc_manifest.rb +25 -2
- data/test/tc_provenance.rb +75 -0
- data/test/tc_proxy.rb +56 -0
- data/test/tc_read.rb +4 -4
- data/test/tc_remove.rb +8 -5
- data/test/tc_util.rb +2 -1
- data/test/ts_ro_bundle.rb +3 -1
- metadata +51 -31
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZDhiYWIxODFjYmNkZWExZGZkZDEzNjkwNmY4OTAwNTQ4M2NhMDZhMQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce96bc8a8dd23d9784601a0c4d5f18f8b94e895e
|
4
|
+
data.tar.gz: 0152f7394f9a3638c3b396e5b9fd02f32a6e07ce
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZjM0ZmRjN2Y5ZWY2MjA1ZmE3MjdiYjRiMDYwNGQ0YjlkODhhN2FkNDZjNzI2
|
11
|
-
MWRiOWEwOGEwYzEyZWJlNDNhNjY4MTU2ZTA2OTU1NWIzMmQ1ODk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NGJkYjkxZmQwMTE3ZTBmZjRmNDQ3YmI2NzhmMTM5NTM5ZDAxMjZhNzQ2NTM1
|
14
|
-
YzUwNGZiNzJjY2QzYWJjMjI3Yjg5NDQxOGFhZGM0YTliZTc1ZjMyMjBlYmIz
|
15
|
-
MTU5OGY0YTg1M2Q5M2FiOTFlZGU1YzRhYzdkOGI4OTQ3YmZmZTM=
|
6
|
+
metadata.gz: 5f6d7d8e6b4e2a547faccc52a2e51e6145db72c24b15185489d9d3f31082d8a667d3b9c621364dc1b044f0819d6a3bb6d78ca51dab026f1fb36e1f062d208694
|
7
|
+
data.tar.gz: 7ca9dba93b88c45218f2afef0eb3c618863be46bf34e9f2aac58682b98d14f604028c9cf378a7968833a5cb95aea6f3f343beca4b861ce6031d93cf423a53cad
|
data/.ruby-gemset
CHANGED
data/.ruby-version
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
ruby-
|
2
|
-
|
1
|
+
ruby-2.2.1
|
data/.travis.yml
CHANGED
data/Licence.rdoc
CHANGED
data/ReadMe.rdoc
CHANGED
@@ -5,16 +5,17 @@ Contact:: mailto:support@mygrid.org.uk
|
|
5
5
|
Homepage:: http://mygrid.github.io/ruby-ro-bundle
|
6
6
|
Source code:: https://github.com/myGrid/ruby-ro-bundle
|
7
7
|
Licence:: BSD (See Licence file or http://www.opensource.org/licenses/bsd-license.php)
|
8
|
-
Copyright:: (c) 2014 The University of Manchester, UK
|
8
|
+
Copyright:: (c) 2014, 2015 The University of Manchester, UK
|
9
9
|
|
10
|
-
{<img src="https://
|
10
|
+
{<img src="https://badge.fury.io/rb/ro-bundle.svg" alt="Gem Version" />}[http://badge.fury.io/rb/ro-bundle]
|
11
|
+
{<img src="https://codeclimate.com/github/myGrid/ruby-ro-bundle.svg" />}[https://codeclimate.com/github/myGrid/ruby-ro-bundle]
|
11
12
|
{<img src="https://travis-ci.org/myGrid/ruby-ro-bundle.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/myGrid/ruby-ro-bundle]
|
12
|
-
{<img src="https://coveralls.io/repos/myGrid/ruby-ro-bundle/badge.
|
13
|
+
{<img src="https://coveralls.io/repos/myGrid/ruby-ro-bundle/badge.svg?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/myGrid/ruby-ro-bundle?branch=master]
|
13
14
|
|
14
15
|
== Synopsis
|
15
16
|
|
16
17
|
This is a Ruby library for working with Research Object Bundle files. See the
|
17
|
-
{Research Object Bundle}[
|
18
|
+
{Research Object Bundle}[https://w3id.org/bundle/] specification
|
18
19
|
for more details.
|
19
20
|
|
20
21
|
<b>This library is a work in progress!</b> Until we release version 1.0.0 you
|
@@ -48,10 +49,10 @@ See the contents of the tests directory for even more example usage.
|
|
48
49
|
|
49
50
|
== What this library cannot do yet
|
50
51
|
|
51
|
-
The {RO Bundle specification}[
|
52
|
+
The {RO Bundle specification}[https://w3id.org/bundle/] is largely
|
52
53
|
implemented but there are notable gaps at present, including:
|
53
54
|
|
54
|
-
* Aggregates do not support ORE proxies yet.
|
55
55
|
* Extra provenance information cannot yet be added using the <tt>pav:</tt>
|
56
56
|
namespace.
|
57
|
-
* The <tt>@graph</tt> member is not supported in the top-level manifest
|
57
|
+
* The <tt>@graph</tt> member is not supported in the top-level manifest
|
58
|
+
(although if it is present it will be preserved).
|
data/bin/dir2ro
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#------------------------------------------------------------------------------
|
3
|
-
# Copyright (c) 2014 The University of Manchester, UK.
|
3
|
+
# Copyright (c) 2014, 2015 The University of Manchester, UK.
|
4
4
|
#
|
5
5
|
# BSD Licenced. See LICENCE.rdoc for details.
|
6
6
|
#
|
@@ -9,6 +9,7 @@
|
|
9
9
|
|
10
10
|
require 'rubygems'
|
11
11
|
require 'ro-bundle'
|
12
|
+
require 'pathname'
|
12
13
|
|
13
14
|
def usage
|
14
15
|
puts "Usage:\n dir2ro <directory> <ro-bundle> [name]"
|
@@ -42,7 +43,7 @@ begin
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
45
|
-
rescue Errno::ENOENT,
|
46
|
+
rescue Errno::ENOENT, ZipContainer::Error => err
|
46
47
|
puts err.to_s
|
47
48
|
exit 1
|
48
49
|
end
|
data/bin/ro-bundle-info
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#------------------------------------------------------------------------------
|
3
|
-
# Copyright (c) 2014 The University of Manchester, UK.
|
3
|
+
# Copyright (c) 2014, 2015 The University of Manchester, UK.
|
4
4
|
#
|
5
5
|
# BSD Licenced. See LICENCE.rdoc for details.
|
6
6
|
#
|
@@ -21,7 +21,7 @@ bundle = ARGV[0]
|
|
21
21
|
|
22
22
|
begin
|
23
23
|
ro = ROBundle::File.open(bundle)
|
24
|
-
rescue ZipContainer::MalformedContainerError, ZipContainer::
|
24
|
+
rescue ZipContainer::MalformedContainerError, ZipContainer::Error => err
|
25
25
|
puts err.to_s
|
26
26
|
exit 1
|
27
27
|
end
|
data/bin/verify-ro-bundle
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#------------------------------------------------------------------------------
|
3
|
-
# Copyright (c) 2014 The University of Manchester, UK.
|
3
|
+
# Copyright (c) 2014, 2015 The University of Manchester, UK.
|
4
4
|
#
|
5
5
|
# BSD Licenced. See LICENCE.rdoc for details.
|
6
6
|
#
|
@@ -21,7 +21,7 @@ rofile = ARGV[0]
|
|
21
21
|
|
22
22
|
begin
|
23
23
|
ROBundle::File.verify!(rofile)
|
24
|
-
rescue ZipContainer::MalformedContainerError, ZipContainer::
|
24
|
+
rescue ZipContainer::MalformedContainerError, ZipContainer::Error => err
|
25
25
|
puts err.to_s
|
26
26
|
exit 1
|
27
27
|
end
|
data/bin/zip2ro
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#------------------------------------------------------------------------------
|
3
|
-
# Copyright (c) 2014 The University of Manchester, UK.
|
3
|
+
# Copyright (c) 2014, 2015 The University of Manchester, UK.
|
4
4
|
#
|
5
5
|
# BSD Licenced. See LICENCE.rdoc for details.
|
6
6
|
#
|
@@ -51,7 +51,7 @@ begin
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
-
rescue Errno::ENOENT,
|
54
|
+
rescue Errno::ENOENT, ZipContainer::Error => err
|
55
55
|
puts err.to_s
|
56
56
|
exit 1
|
57
57
|
end
|
data/lib/ro-bundle.rb
CHANGED
@@ -19,6 +19,8 @@ require "ro-bundle/util"
|
|
19
19
|
require "ro-bundle/exceptions"
|
20
20
|
require "ro-bundle/ro/agent"
|
21
21
|
require "ro-bundle/ro/provenance"
|
22
|
+
require "ro-bundle/ro/manifest-entry"
|
23
|
+
require "ro-bundle/ro/proxy"
|
22
24
|
require "ro-bundle/ro/annotation"
|
23
25
|
require "ro-bundle/ro/aggregate"
|
24
26
|
require "ro-bundle/ro/manifest"
|
@@ -29,8 +31,7 @@ require "ro-bundle/file"
|
|
29
31
|
# Zip format. See the ROBundle::File class for more information.
|
30
32
|
#
|
31
33
|
# See
|
32
|
-
# {the RO Bundle specification}[
|
33
|
-
# for more details.
|
34
|
+
# {the RO Bundle specification}[https://w3id.org/bundle/] for more details.
|
34
35
|
#
|
35
36
|
# Most of this library's API is provided by two underlying gems. Please
|
36
37
|
# consult their documentation in addition to this:
|
data/lib/ro-bundle/exceptions.rb
CHANGED
@@ -13,18 +13,4 @@ module ROBundle
|
|
13
13
|
class ROError < RuntimeError
|
14
14
|
end
|
15
15
|
|
16
|
-
# This exception is raised when an invalid aggregate is detected.
|
17
|
-
class InvalidAggregateError < ROError
|
18
|
-
|
19
|
-
# :call-seq:
|
20
|
-
# new(name)
|
21
|
-
#
|
22
|
-
# Create a new InvalidAggregateError with the invalid object (file or
|
23
|
-
# URI) supplied.
|
24
|
-
def initialize(object)
|
25
|
-
super("'#{object}' is not an absolute filename or a URI.")
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
16
|
end
|
data/lib/ro-bundle/file.rb
CHANGED
@@ -10,8 +10,7 @@
|
|
10
10
|
module ROBundle
|
11
11
|
|
12
12
|
# This class represents a Research Object Bundle file. See the
|
13
|
-
# {RO Bundle specification}[
|
14
|
-
# for more details.
|
13
|
+
# {RO Bundle specification}[https://w3id.org/bundle/] for more details.
|
15
14
|
#
|
16
15
|
# Many of the methods that this class provides are actually implemented in
|
17
16
|
# the Manifest class, so please see its documentation for details.
|
@@ -35,12 +34,6 @@ module ROBundle
|
|
35
34
|
@manifest = Manifest.new
|
36
35
|
@ro_dir = RODir.new(@manifest)
|
37
36
|
initialize_managed_entries(@ro_dir)
|
38
|
-
|
39
|
-
# Create the .ro directory if it does not already exist.
|
40
|
-
if find_entry(@ro_dir.full_name).nil?
|
41
|
-
mkdir(@ro_dir.full_name)
|
42
|
-
commit
|
43
|
-
end
|
44
37
|
end
|
45
38
|
# :startdoc:
|
46
39
|
|
@@ -59,7 +52,20 @@ module ROBundle
|
|
59
52
|
# for much more information and a list of all the other methods available
|
60
53
|
# in this class. RDoc does not list inherited methods, unfortunately.
|
61
54
|
def self.create(filename, mimetype = MIMETYPE, &block)
|
62
|
-
|
55
|
+
# Wow. I have to specifically send nil as the block to stop super from
|
56
|
+
# sending the other block up automatically. Is this a bug in Ruby?
|
57
|
+
ro = super(filename, mimetype, &nil)
|
58
|
+
ro.init_metadata
|
59
|
+
|
60
|
+
if block_given?
|
61
|
+
begin
|
62
|
+
yield ro
|
63
|
+
ensure
|
64
|
+
ro.close
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
ro
|
63
69
|
end
|
64
70
|
|
65
71
|
# :call-seq:
|
@@ -189,9 +195,7 @@ module ROBundle
|
|
189
195
|
end
|
190
196
|
|
191
197
|
aggregates.each do |agg|
|
192
|
-
return true if agg.uri == entry ||
|
193
|
-
agg.file == entry ||
|
194
|
-
agg.file_entry == entry
|
198
|
+
return true if agg.uri == entry || agg.file_entry == entry
|
195
199
|
end
|
196
200
|
|
197
201
|
false
|
@@ -213,10 +217,10 @@ module ROBundle
|
|
213
217
|
#
|
214
218
|
# Is the supplied id or annotation registered in this Research Object?
|
215
219
|
def annotation?(id)
|
216
|
-
id = id.
|
220
|
+
id = id.uri if id.instance_of?(Annotation)
|
217
221
|
|
218
222
|
annotations.each do |ann|
|
219
|
-
return true if ann.
|
223
|
+
return true if ann.uri == id
|
220
224
|
end
|
221
225
|
|
222
226
|
false
|
@@ -231,12 +235,8 @@ module ROBundle
|
|
231
235
|
# otherwise.
|
232
236
|
def commit
|
233
237
|
if @manifest.edited?
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
file.open(name, "w") do |m|
|
238
|
-
m.puts JSON.pretty_generate(@manifest)
|
239
|
-
end
|
238
|
+
# This will overwrite the old version.
|
239
|
+
@manifest.write
|
240
240
|
|
241
241
|
@ro_dir.cleanup_annotation_data
|
242
242
|
end
|
@@ -319,5 +319,13 @@ module ROBundle
|
|
319
319
|
@manifest.remove_aggregate(object)
|
320
320
|
end
|
321
321
|
|
322
|
+
# :stopdoc:
|
323
|
+
def init_metadata
|
324
|
+
mkdir(@ro_dir.full_name)
|
325
|
+
@manifest.init
|
326
|
+
commit
|
327
|
+
end
|
328
|
+
# :startdoc:
|
329
|
+
|
322
330
|
end
|
323
331
|
end
|
data/lib/ro-bundle/ro/agent.rb
CHANGED
@@ -11,35 +11,40 @@ module ROBundle
|
|
11
11
|
|
12
12
|
# A class to represent an aggregated resource in a Research Object. It holds
|
13
13
|
# standard meta-data for either file or URI resources. An aggregate can only
|
14
|
-
# represent a file OR a URI resource, not both at once.
|
15
|
-
|
16
|
-
|
14
|
+
# represent a file path OR a URI resource, not both at once.
|
15
|
+
#
|
16
|
+
# If a file path is passed, it will be correctly encoded into a valid absolute URI. If an absolute URI is passed, it is
|
17
|
+
# assumed to already have been encoded.
|
18
|
+
class Aggregate < ManifestEntry
|
17
19
|
|
18
20
|
# :call-seq:
|
19
|
-
# new(
|
20
|
-
# new(
|
21
|
+
# new(uri, mediatype)
|
22
|
+
# new(uri)
|
23
|
+
# new(filepath)
|
24
|
+
# new(filepath, mediatype)
|
21
25
|
#
|
22
26
|
# Create a new file or URI aggregate.
|
23
|
-
def initialize(object,
|
24
|
-
|
27
|
+
def initialize(object, mediatype = nil)
|
28
|
+
super()
|
25
29
|
|
26
30
|
if object.instance_of?(Hash)
|
27
31
|
init_json(object)
|
28
32
|
else
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
@structure[:uri] = if Util.is_absolute_uri?(object)
|
34
|
+
object.to_s
|
35
|
+
else
|
36
|
+
URI.encode(object.start_with?("/") ? object : "/#{object}")
|
37
|
+
end
|
38
|
+
@structure[:mediatype] = mediatype
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
42
|
# :call-seq:
|
38
|
-
#
|
43
|
+
# edited? -> true or false
|
39
44
|
#
|
40
|
-
#
|
41
|
-
def
|
42
|
-
@
|
45
|
+
# Has this aggregate been altered in any way?
|
46
|
+
def edited?
|
47
|
+
@edited || (proxy.nil? ? false : proxy.edited?)
|
43
48
|
end
|
44
49
|
|
45
50
|
# :call-seq:
|
@@ -47,7 +52,7 @@ module ROBundle
|
|
47
52
|
#
|
48
53
|
# The path of this aggregate in "rubyzip" format, i.e. no leading '/'.
|
49
54
|
def file_entry
|
50
|
-
Util.strip_leading_slash(
|
55
|
+
URI.decode(Util.strip_leading_slash(uri)) unless Util.is_absolute_uri?(uri)
|
51
56
|
end
|
52
57
|
|
53
58
|
# :call-seq:
|
@@ -61,44 +66,47 @@ module ROBundle
|
|
61
66
|
# :call-seq:
|
62
67
|
# mediatype
|
63
68
|
#
|
64
|
-
#
|
69
|
+
# This aggregate's
|
65
70
|
# {IANA media type}[http://www.iana.org/assignments/media-types].
|
66
71
|
def mediatype
|
67
72
|
@structure[:mediatype]
|
68
73
|
end
|
69
74
|
|
75
|
+
# :call-seq:
|
76
|
+
# proxy -> Proxy
|
77
|
+
#
|
78
|
+
# Return this aggregate's ORE proxy as per the specification of the
|
79
|
+
# {JSON structure}[https://researchobject.github.io/specifications/bundle/#json-structure]
|
80
|
+
# of the manifest.
|
81
|
+
def proxy
|
82
|
+
@structure[:bundledAs]
|
83
|
+
end
|
84
|
+
|
70
85
|
# :call-seq:
|
71
86
|
# to_json(options = nil) -> String
|
72
87
|
#
|
73
88
|
# Write this Aggregate out as a json string. Takes the same options as
|
74
89
|
# JSON#generate.
|
75
90
|
def to_json(*a)
|
76
|
-
Util.clean_json(@structure)
|
91
|
+
JSON.generate(Util.clean_json(@structure),*a)
|
77
92
|
end
|
78
93
|
|
79
|
-
|
80
|
-
|
81
|
-
def
|
82
|
-
|
94
|
+
# :stopdoc:
|
95
|
+
# For internal use only!
|
96
|
+
def stored
|
97
|
+
super
|
98
|
+
proxy.stored unless proxy.nil?
|
83
99
|
end
|
100
|
+
# :startdoc:
|
101
|
+
|
102
|
+
private
|
84
103
|
|
85
104
|
def init_json(object)
|
86
|
-
init_file_or_uri(object[:file] || object[:uri])
|
87
105
|
@structure = init_provenance_defaults(object)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
def init_file_or_uri(object)
|
95
|
-
if object.is_a?(String) && !Util.is_absolute_uri?(object)
|
96
|
-
name = object.start_with?("/") ? object : "/#{object}"
|
97
|
-
@structure[:file] = name
|
98
|
-
elsif Util.is_absolute_uri?(object)
|
99
|
-
@structure[:uri] = object.to_s
|
100
|
-
else
|
101
|
-
raise InvalidAggregateError.new(object)
|
106
|
+
@structure[:uri] = object[:uri]
|
107
|
+
@structure[:mediatype] = object[:mediatype]
|
108
|
+
unless object[:bundledAs].nil?
|
109
|
+
@structure[:bundledAs] = Proxy.new(object[:bundledAs])
|
102
110
|
end
|
103
111
|
end
|
104
112
|
|