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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzZiZjc4MTE0OTMyM2Q2ZDhiMDY1Yjk1MTY4NjgwNDc1YTAzY2I1NA==
5
- data.tar.gz: !binary |-
6
- ZDhiYWIxODFjYmNkZWExZGZkZDEzNjkwNmY4OTAwNTQ4M2NhMDZhMQ==
2
+ SHA1:
3
+ metadata.gz: ce96bc8a8dd23d9784601a0c4d5f18f8b94e895e
4
+ data.tar.gz: 0152f7394f9a3638c3b396e5b9fd02f32a6e07ce
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZWQyYjRmZjY1YWQyODE2YTAzN2Y5YzI1NTliMzgwYjY5M2RmNDk1MmQ3ODJj
10
- ZjM0ZmRjN2Y5ZWY2MjA1ZmE3MjdiYjRiMDYwNGQ0YjlkODhhN2FkNDZjNzI2
11
- MWRiOWEwOGEwYzEyZWJlNDNhNjY4MTU2ZTA2OTU1NWIzMmQ1ODk=
12
- data.tar.gz: !binary |-
13
- NGJkYjkxZmQwMTE3ZTBmZjRmNDQ3YmI2NzhmMTM5NTM5ZDAxMjZhNzQ2NTM1
14
- YzUwNGZiNzJjY2QzYWJjMjI3Yjg5NDQxOGFhZGM0YTliZTc1ZjMyMjBlYmIz
15
- MTU5OGY0YTg1M2Q5M2FiOTFlZGU1YzRhYzdkOGI4OTQ3YmZmZTM=
6
+ metadata.gz: 5f6d7d8e6b4e2a547faccc52a2e51e6145db72c24b15185489d9d3f31082d8a667d3b9c621364dc1b044f0819d6a3bb6d78ca51dab026f1fb36e1f062d208694
7
+ data.tar.gz: 7ca9dba93b88c45218f2afef0eb3c618863be46bf34e9f2aac58682b98d14f604028c9cf378a7968833a5cb95aea6f3f343beca4b861ce6031d93cf423a53cad
@@ -1,2 +1 @@
1
1
  ro-bundle
2
-
@@ -1,2 +1 @@
1
- ruby-1.9.3
2
-
1
+ ruby-2.2.1
@@ -1,11 +1,19 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0.0
5
- - 2.1.2
6
+ - 2.1.6
7
+ - 2.2.1
6
8
  - ruby-head
7
9
  - rbx-2
10
+
11
+ sudo: false
12
+
13
+ cache: bundler
14
+
8
15
  matrix:
9
16
  allow_failures:
17
+ - rvm: 1.9.3
10
18
  - rvm: ruby-head
11
19
  - rvm: rbx-2
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 The University of Manchester, UK.
1
+ Copyright (c) 2014, 2015 The University of Manchester, UK.
2
2
 
3
3
  All rights reserved.
4
4
 
@@ -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://codeclimate.com/github/myGrid/ruby-ro-bundle.png" />}[https://codeclimate.com/github/myGrid/ruby-ro-bundle]
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.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/myGrid/ruby-ro-bundle?branch=master]
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}[http://wf4ever.github.io/ro/bundle/] specification
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}[http://wf4ever.github.io/ro/bundle/] is largely
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, Zip::Error => err
46
+ rescue Errno::ENOENT, ZipContainer::Error => err
46
47
  puts err.to_s
47
48
  exit 1
48
49
  end
@@ -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::ZipError => err
24
+ rescue ZipContainer::MalformedContainerError, ZipContainer::Error => err
25
25
  puts err.to_s
26
26
  exit 1
27
27
  end
@@ -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::ZipError => err
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, Zip::Error => err
54
+ rescue Errno::ENOENT, ZipContainer::Error => err
55
55
  puts err.to_s
56
56
  exit 1
57
57
  end
@@ -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}[http://wf4ever.github.io/ro/bundle/]
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:
@@ -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
@@ -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}[http://wf4ever.github.io/ro/bundle/]
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
- super(filename, mimetype, &block)
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.annotation_id if id.instance_of?(Annotation)
220
+ id = id.uri if id.instance_of?(Annotation)
217
221
 
218
222
  annotations.each do |ann|
219
- return true if ann.annotation_id == id
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
- name = @manifest.full_name
235
- remove(name, true) unless find_entry(name).nil?
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
@@ -65,7 +65,7 @@ module ROBundle
65
65
  # Write this Agent out as a json string. Takes the same options as
66
66
  # JSON#generate.
67
67
  def to_json(*a)
68
- Util.clean_json(@structure).to_json(*a)
68
+ JSON.generate(Util.clean_json(@structure),*a)
69
69
  end
70
70
 
71
71
  end
@@ -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
- class Aggregate
16
- include Provenance
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(filename, mediatype = nil)
20
- # new(URI)
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, second = nil)
24
- @structure = {}
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
- init_file_or_uri(object)
30
-
31
- if @structure[:file]
32
- @structure[:mediatype] = second
33
- end
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
- # file
43
+ # edited? -> true or false
39
44
  #
40
- # The path of this aggregate. It should start with '/'.
41
- def file
42
- @structure[:file]
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(file)
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
- # For a file aggregate, its
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).to_json(*a)
91
+ JSON.generate(Util.clean_json(@structure),*a)
77
92
  end
78
93
 
79
- private
80
-
81
- def structure
82
- @structure
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
- if @structure[:file]
90
- @structure[:mediatype] = object[:mediatype]
91
- end
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