rdf-ldp 0.5.1 → 0.6.0

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
  SHA1:
3
- metadata.gz: d1fb8fbd183ec6b222e4a1d8f70c95a530111e09
4
- data.tar.gz: fe49505fd5a0b6442af69f691ffc4450e7a301a2
3
+ metadata.gz: 51911c93db2822f4b81a715187dbe77ea175336d
4
+ data.tar.gz: 1109c3c631c59d55ff0e96e422d29363e1efcc61
5
5
  SHA512:
6
- metadata.gz: 35cefba9e0d2cd219d63cca897bf423950f5baa9de5eed003c47d6e4166688beb328e00f07e56541c6e871f2dcad1bdc5cf1af31e8d9af0cfe3c6c8aa16c53a8
7
- data.tar.gz: 9dfb9d04d821a4058b087ea1ebc5559ec03d26186e8356ec698cf5576b8afe06ef478fcc17f1b48f27b1988e0e92b9ccecdae83cea642df14a184c5fb19d487d
6
+ metadata.gz: 86057aa53d6be3dad23e16107da011b30b8e3ba039bec87dd77c0729ced5a3775c363528df35124860e70bb5ea718fb59708d44585d1523ce29ab195d803c05b
7
+ data.tar.gz: 3f6824f3c638733ac1f66c6eecbfb8856ada627ef9156453c9ba61ee45316f09fadefac59e35436324e6ee64f7e75c05d23eed5266a289ea5d67a3f7a81de11c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ 0.6.0
2
+ -----
3
+ - Upgrades to RDF.rb 2.0
4
+ - Adds true transaction scopes for POST & PUT requests
5
+ - Changes behavior of direct & indirect containers to add default
6
+ required triples on creation if none are supplied in the request.
7
+
1
8
  0.5.1
2
9
  -----
3
10
  - Fixes inserted content relation interpretations.
data/README.md CHANGED
@@ -111,6 +111,14 @@ Reports are generated by the LDP test suite. To duplicate the results,
111
111
  use the `testsuite` branch, which contains a work-around for
112
112
  [w3c/ldp-testsuite#224](https://github.com/w3c/ldp-testsuite/issues/224).
113
113
 
114
+ RDF.rb 1.x Compatibility
115
+ --------------------------
116
+
117
+ As of version 0.6.0, this software depends on RDF.rb 2.0 or greater. Support for
118
+ Ruby RDF version 1.99 will be maintained to the degree possible on the 0.5.x
119
+ release series. Users are encouraged to upgrade their projects to 2.0 to take
120
+ advantage of the latest development.
121
+
114
122
 
115
123
  License
116
124
  ========
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.6.0
@@ -120,7 +120,7 @@ module RDF::LDP
120
120
  # @return [Container] self
121
121
  def add_containment_triple(resource, transaction = nil)
122
122
  target = transaction || graph
123
- target << make_containment_triple(resource)
123
+ target.insert make_containment_triple(resource)
124
124
  set_last_modified(transaction)
125
125
  self
126
126
  end
@@ -201,28 +201,18 @@ module RDF::LDP
201
201
  def validate_triples!(transaction)
202
202
  existing_triples = containment_triples.to_a
203
203
 
204
- inserts = transaction.inserts.select do |st|
205
- st.subject == subject_uri && st.predicate == RDF::Vocab::LDP.contains
206
- end
204
+ tx_containment = transaction.query(subject: subject_uri,
205
+ predicate: RDF::Vocab::LDP.contains)
207
206
 
208
- inserts.each do |statement|
209
- existing_triples.delete(statement) do
210
- raise Conflict.new('Attempted to write unacceptable LDP ' \
211
- "containment-triple: #{statement}")
212
- end
207
+ tx_containment.each do |statement|
208
+ raise Conflict.new('Attempted to write unacceptable LDP ' \
209
+ "containment-triple: #{statement}") unless
210
+ existing_triples.include?(statement)
213
211
  end
214
212
 
215
- deletes = transaction.deletes.select do |st|
216
- st.subject == subject_uri &&
217
- predicate == RDF::Vocab::LDP.contains &&
218
- !inserts.include?(st)
219
- end
220
-
221
- deletes = deletes + existing_triples
222
-
213
+ deletes = existing_triples.reject { |st| tx_containment.include?(st) }
223
214
  raise Conflict.new('Cannot remove containment triples in updates. ' \
224
- "Attepted to remove #{deletes}") unless
225
- deletes.empty?
215
+ "Attepted to remove #{deletes}") unless deletes.empty?
226
216
  end
227
217
 
228
218
  ##
@@ -32,7 +32,22 @@ module RDF::LDP
32
32
  end
33
33
 
34
34
  ##
35
- # Adds a member `resource` to the container. Handles containment and adds
35
+ # @see Container#create
36
+ def create(input, content_type, &block)
37
+ super
38
+ # insert relation triples after the transaction, since we can't guarantee
39
+ # snapshot access.
40
+ #
41
+ # @todo consider just raising an error instead.
42
+ graph.insert(default_member_relation_statement) if
43
+ member_relation_statements.empty?
44
+ graph.insert(default_membership_resource_statement) if
45
+ membership_resource_statements.empty?
46
+ self
47
+ end
48
+
49
+ ##
50
+ # Adds a member `resource` to the container. Handles containment and adds
36
51
  # membership triple to the memebership resource.
37
52
  #
38
53
  # @see RDF::LDP::Container#add
@@ -41,7 +56,7 @@ module RDF::LDP
41
56
  process_membership_resource(resource) do |membership, quad, resource|
42
57
  super(resource, transaction)
43
58
  target = transaction || membership.graph
44
- target << quad
59
+ target.insert(quad)
45
60
  end
46
61
  self
47
62
  end
@@ -71,19 +86,10 @@ module RDF::LDP
71
86
  # @see http://www.w3.org/TR/ldp/#dfn-membership-triples
72
87
  def membership_constant_uri
73
88
  statements = membership_resource_statements
74
- case statements.count
75
- when 0
76
- graph << RDF::Statement(subject_uri,
77
- RDF::Vocab::LDP.membershipResource,
78
- subject_uri)
79
- subject_uri
80
- when 1
81
- statements.first.object
82
- else
83
- raise NotAcceptable.new('An LDP-DC MUST have exactly ' \
84
- 'one membership resource; found ' \
85
- "#{statements}.")
86
- end
89
+ return statements.first.object if statements.count == 1
90
+
91
+ raise NotAcceptable.new('An LDP-DC MUST have exactly one membership ' \
92
+ "resource; found #{statements.count}.")
87
93
  end
88
94
 
89
95
  ##
@@ -97,19 +103,10 @@ module RDF::LDP
97
103
  # @see http://www.w3.org/TR/ldp/#dfn-membership-predicate
98
104
  def membership_predicate
99
105
  statements = member_relation_statements
100
- case statements.count
101
- when 0
102
- graph << RDF::Statement(subject_uri,
103
- RELATION_TERMS.first,
104
- RDF::Vocab::LDP.member)
105
- RDF::Vocab::LDP.member
106
- when 1
107
- statements.first.object
108
- else
109
- raise NotAcceptable.new('An LDP-DC MUST have exactly ' \
110
- 'one member relation triple; found ' \
111
- "#{statements.count}.")
112
- end
106
+ return statements.first.object if statements.count == 1
107
+
108
+ raise NotAcceptable.new('An LDP-DC MUST have exactly one member ' \
109
+ "relation triple; found #{statements.count}.")
113
110
  end
114
111
 
115
112
  ##
@@ -159,5 +156,15 @@ module RDF::LDP
159
156
  statement.graph_name = membership_rs.subject_uri
160
157
  yield(membership_rs, statement, resource) if block_given?
161
158
  end
159
+
160
+ def default_membership_resource_statement
161
+ RDF::Statement(subject_uri,
162
+ RDF::Vocab::LDP.membershipResource,
163
+ subject_uri)
164
+ end
165
+
166
+ def default_member_relation_statement
167
+ RDF::Statement(subject_uri, RELATION_TERMS.first, RDF::Vocab::LDP.member)
168
+ end
162
169
  end
163
170
  end
@@ -28,6 +28,17 @@ module RDF::LDP
28
28
  CONTAINER_CLASSES[:indirect]
29
29
  end
30
30
 
31
+ ##
32
+ # @see Container#create
33
+ def create(input, content_type, &block)
34
+ super
35
+ graph.insert RDF::Statement(subject_uri,
36
+ RDF::Vocab::LDP.insertedContentRelation,
37
+ RDF::Vocab::LDP.MemberSubject) if
38
+ inserted_content_statements.empty?
39
+ self
40
+ end
41
+
31
42
  ##
32
43
  # Gives the inserted content relation for the indirect container. If none is
33
44
  # present in the container state, we add `ldp:MemberSubject`, effectively
@@ -42,19 +53,11 @@ module RDF::LDP
42
53
  # @see http://www.w3.org/TR/ldp/#dfn-membership-triples
43
54
  def inserted_content_relation
44
55
  statements = inserted_content_statements
45
- case statements.count
46
- when 0
47
- graph << RDF::Statement(subject_uri,
48
- RDF::Vocab::LDP.insertedContentRelation,
49
- RDF::Vocab::LDP.MemberSubject)
50
- RDF::Vocab::LDP.MemberSubject
51
- when 1
52
- statements.first.object
53
- else
54
- raise NotAcceptable.new('An LDP-IC MUST have exactly ' \
55
- 'one inserted content relation triple; found ' \
56
- "#{statements.count}.")
57
- end
56
+ return statements.first.object if statements.count == 1
57
+
58
+ raise NotAcceptable.new('An LDP-IC MUST have exactly ' \
59
+ 'one inserted content relation triple; found ' \
60
+ "#{statements.count}.")
58
61
  end
59
62
 
60
63
  private
@@ -76,17 +79,12 @@ module RDF::LDP
76
79
  raise NotAcceptable.new("#{resource.to_uri} is an LDP-NR; cannot add " \
77
80
  'it to an IndirectContainer with a content ' \
78
81
  'relation.') if resource.non_rdf_source?
79
-
80
- resource
81
82
 
82
83
  statements = resource.graph.query([resource.subject_uri, predicate, :o])
83
- case statements.count
84
- when 1
85
- statements.first.object
86
- else
87
- raise NotAcceptable.new("#{statements.count} inserted content" \
88
- "#{predicate} found on #{resource.to_uri}")
89
- end
84
+ return statements.first.object if statements.count == 1
85
+
86
+ raise NotAcceptable.new("#{statements.count} inserted content" \
87
+ "#{predicate} found on #{resource.to_uri}")
90
88
  end
91
89
  end
92
90
  end
@@ -102,7 +102,8 @@ module RDF::LDP
102
102
  # @return [StorageAdapter] the content type
103
103
  def content_type=(content_type)
104
104
  metagraph.delete([subject_uri, FORMAT_TERM])
105
- metagraph << RDF::Statement(subject_uri, RDF::DC11.format, content_type)
105
+ metagraph <<
106
+ RDF::Statement(subject_uri, RDF::Vocab::DC11.format, content_type)
106
107
  end
107
108
 
108
109
  ##
@@ -53,7 +53,7 @@ module RDF::LDP
53
53
  # @return [RDF::Graph] a graph representing the current persistent state of
54
54
  # the resource.
55
55
  def graph
56
- @graph ||= RDF::Graph.new(@subject_uri, data: @data)
56
+ @graph ||= RDF::Graph.new(graph_name: @subject_uri, data: @data)
57
57
  end
58
58
 
59
59
  ##
@@ -98,9 +98,8 @@ module RDF::LDP
98
98
  # @return [RDF::LDP::Resource] self
99
99
  def create(input, content_type, &block)
100
100
  super do |transaction|
101
- transaction.graph_name = subject_uri
102
101
  statements = parse_graph(input, content_type)
103
- transaction << statements
102
+ transaction.insert(statements)
104
103
  yield transaction if block_given?
105
104
  end
106
105
  end
@@ -134,12 +133,10 @@ module RDF::LDP
134
133
  # @return [RDF::LDP::Resource] self
135
134
  def update(input, content_type, &block)
136
135
  super do |transaction|
137
- transaction.graph_name = subject_uri
138
- transaction << parse_graph(input, content_type)
136
+ transaction.delete(RDF::Statement(nil, nil, nil, graph_name: subject_uri))
137
+ transaction.insert parse_graph(input, content_type)
139
138
  yield transaction if block_given?
140
- graph.clear
141
139
  end
142
-
143
140
  self
144
141
  end
145
142
 
@@ -148,8 +145,8 @@ module RDF::LDP
148
145
  #
149
146
  # @see RDF::LDP::Resource#destroy
150
147
  def destroy(&block)
151
- super do |_|
152
- graph.clear
148
+ super do |tx|
149
+ tx.delete(RDF::Statement(nil, nil, nil, graph_name: subject_uri))
153
150
  end
154
151
  end
155
152
 
@@ -242,17 +239,17 @@ module RDF::LDP
242
239
  #
243
240
  # @raise [RDF::LDP::UnsupportedMediaType] if no appropriate reader is found
244
241
  #
245
- # @todo handle cases where no content type is given? Does RDF::Reader have
246
- # tools to help us here?
247
- #
248
242
  # @see http://www.rubydoc.info/github/rack/rack/file/SPEC#The_Input_Stream
249
243
  # for documentation on input streams in the Rack SPEC
250
244
  def parse_graph(input, content_type)
251
245
  reader = RDF::Reader.for(content_type: content_type.to_s)
252
246
  raise(RDF::LDP::UnsupportedMediaType, content_type) if reader.nil?
247
+
253
248
  input = input.read if input.respond_to? :read
249
+
254
250
  begin
255
- RDF::Graph.new << reader.new(input, base_uri: subject_uri, validate: true)
251
+ RDF::Graph.new(graph_name: subject_uri, data: RDF::Repository.new) <<
252
+ reader.new(input, base_uri: subject_uri, validate: true)
256
253
  rescue RDF::ReaderError => e
257
254
  raise RDF::LDP::BadRequest, e.message
258
255
  end
@@ -125,7 +125,7 @@ module RDF::LDP
125
125
  # usually of a subclass
126
126
  # from the interaction models.
127
127
  def find(uri, data)
128
- graph = RDF::Graph.new(metagraph_name(uri), data: data)
128
+ graph = RDF::Graph.new(graph_name: metagraph_name(uri), data: data)
129
129
  raise NotFound if graph.empty?
130
130
 
131
131
  rdf_class = graph.query([uri, RDF.type, :o]).first
@@ -196,7 +196,7 @@ module RDF::LDP
196
196
  def initialize(subject_uri, data = RDF::Repository.new)
197
197
  @subject_uri = RDF::URI(subject_uri)
198
198
  @data = data
199
- @metagraph = RDF::Graph.new(metagraph_name, data: data)
199
+ @metagraph = RDF::Graph.new(graph_name: metagraph_name, data: data)
200
200
  yield self if block_given?
201
201
  end
202
202
 
@@ -220,7 +220,7 @@ module RDF::LDP
220
220
  def create(input, content_type, &block)
221
221
  raise Conflict if exists?
222
222
 
223
- @data.transaction do |transaction|
223
+ @data.transaction(mutable: true) do |transaction|
224
224
  set_interaction_model(transaction)
225
225
  yield transaction if block_given?
226
226
  set_last_modified(transaction)
@@ -246,7 +246,7 @@ module RDF::LDP
246
246
  # subclasses for the appropriate response codes.
247
247
  def update(input, content_type, &block)
248
248
  return create(input, content_type, &block) unless exists?
249
- @data.transaction do |transaction|
249
+ @data.transaction(mutable: true) do |transaction|
250
250
  yield transaction if block_given?
251
251
  set_last_modified(transaction)
252
252
  end
@@ -267,13 +267,13 @@ module RDF::LDP
267
267
  # @todo Use of owl:Nothing is probably problematic. Define an internal
268
268
  # namespace and class represeting deletion status as a stateful property.
269
269
  def destroy(&block)
270
- @data.transaction do |transaction|
270
+ @data.transaction(mutable: true) do |transaction|
271
271
  containers.each { |c| c.remove(self, transaction) if c.container? }
272
- transaction << RDF::Statement(subject_uri,
272
+ transaction.insert RDF::Statement(subject_uri,
273
273
  RDF::Vocab::PROV.invalidatedAtTime,
274
274
  DateTime.now,
275
275
  graph_name: metagraph_name)
276
- yield if block_given?
276
+ yield transaction if block_given?
277
277
  end
278
278
  self
279
279
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-ldp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-09 00:00:00.000000000 Z
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -30,68 +30,56 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.99'
33
+ version: 2.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.99'
40
+ version: 2.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdf-turtle
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
45
  - - ">="
49
46
  - !ruby/object:Gem::Version
50
- version: 1.1.8
47
+ version: '0'
51
48
  type: :runtime
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '1.1'
58
52
  - - ">="
59
53
  - !ruby/object:Gem::Version
60
- version: 1.1.8
54
+ version: '0'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: ld-patch
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: '0.1'
61
+ version: '0.3'
68
62
  type: :runtime
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
- version: '0.1'
68
+ version: '0.3'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: rdf-vocab
77
71
  requirement: !ruby/object:Gem::Requirement
78
72
  requirements:
79
73
  - - "~>"
80
74
  - !ruby/object:Gem::Version
81
- version: '0.8'
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: 0.8.4
75
+ version: '2.0'
85
76
  type: :runtime
86
77
  prerelease: false
87
78
  version_requirements: !ruby/object:Gem::Requirement
88
79
  requirements:
89
80
  - - "~>"
90
81
  - !ruby/object:Gem::Version
91
- version: '0.8'
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: 0.8.4
82
+ version: '2.0'
95
83
  - !ruby/object:Gem::Dependency
96
84
  name: rack-linkeddata
97
85
  requirement: !ruby/object:Gem::Requirement
@@ -112,14 +100,14 @@ dependencies:
112
100
  requirements:
113
101
  - - "~>"
114
102
  - !ruby/object:Gem::Version
115
- version: '1.1'
103
+ version: '2.0'
116
104
  type: :runtime
117
105
  prerelease: false
118
106
  version_requirements: !ruby/object:Gem::Requirement
119
107
  requirements:
120
108
  - - "~>"
121
109
  - !ruby/object:Gem::Version
122
- version: '1.1'
110
+ version: '2.0'
123
111
  - !ruby/object:Gem::Dependency
124
112
  name: sinatra
125
113
  requirement: !ruby/object:Gem::Requirement
@@ -160,62 +148,56 @@ dependencies:
160
148
  requirements:
161
149
  - - "~>"
162
150
  - !ruby/object:Gem::Version
163
- version: '1.1'
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: 1.1.13
151
+ version: '2.0'
167
152
  type: :development
168
153
  prerelease: false
169
154
  version_requirements: !ruby/object:Gem::Requirement
170
155
  requirements:
171
156
  - - "~>"
172
157
  - !ruby/object:Gem::Version
173
- version: '1.1'
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- version: 1.1.13
158
+ version: '2.0'
177
159
  - !ruby/object:Gem::Dependency
178
160
  name: rdf-rdfxml
179
161
  requirement: !ruby/object:Gem::Requirement
180
162
  requirements:
181
163
  - - "~>"
182
164
  - !ruby/object:Gem::Version
183
- version: '1.1'
165
+ version: '2.0'
184
166
  type: :development
185
167
  prerelease: false
186
168
  version_requirements: !ruby/object:Gem::Requirement
187
169
  requirements:
188
170
  - - "~>"
189
171
  - !ruby/object:Gem::Version
190
- version: '1.1'
172
+ version: '2.0'
191
173
  - !ruby/object:Gem::Dependency
192
174
  name: rdf-rdfa
193
175
  requirement: !ruby/object:Gem::Requirement
194
176
  requirements:
195
177
  - - "~>"
196
178
  - !ruby/object:Gem::Version
197
- version: '1.1'
179
+ version: '2.0'
198
180
  type: :development
199
181
  prerelease: false
200
182
  version_requirements: !ruby/object:Gem::Requirement
201
183
  requirements:
202
184
  - - "~>"
203
185
  - !ruby/object:Gem::Version
204
- version: '1.1'
186
+ version: '2.0'
205
187
  - !ruby/object:Gem::Dependency
206
188
  name: rdf-xsd
207
189
  requirement: !ruby/object:Gem::Requirement
208
190
  requirements:
209
191
  - - "~>"
210
192
  - !ruby/object:Gem::Version
211
- version: '1.1'
193
+ version: '2.0'
212
194
  type: :development
213
195
  prerelease: false
214
196
  version_requirements: !ruby/object:Gem::Requirement
215
197
  requirements:
216
198
  - - "~>"
217
199
  - !ruby/object:Gem::Version
218
- version: '1.1'
200
+ version: '2.0'
219
201
  - !ruby/object:Gem::Dependency
220
202
  name: rest-client
221
203
  requirement: !ruby/object:Gem::Requirement