rdf-ldp 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/VERSION +1 -1
- data/lib/rdf/ldp/resource.rb +101 -85
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4eb2d5a31b16d4ec608a5e86604f0e6aa62b74a7
|
4
|
+
data.tar.gz: 364e5044ef73ed29309ecfeed26264b873422692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d2ca4e335869bc99aec018195ad7d42b89395eaed9166bd0313d6de850bbbe8dd91161626ca0552e92102bb5122edc1afb27bc6c810d3703e6ddc3f608ccf09
|
7
|
+
data.tar.gz: b9c3fb8d7ebd10297d55f8c90a5c1ada5ba09bc1d5f9dbd158ed8ad8d8c8e692c7a98a71162f4ad0be8e075365a651dc6bdac0c21d601e4f22ec3520f39b76d0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
0.5.0
|
2
|
+
-----
|
3
|
+
- Fixes error that caused resources to be misidentified when trailing
|
4
|
+
slashes are present.
|
5
|
+
- Returns a 500 error and a useful message when `last_modified` is
|
6
|
+
missing.
|
7
|
+
|
8
|
+
0.4.0
|
9
|
+
-----
|
10
|
+
- Adds Last-Modified and updates ETag strategy to weak etags based on
|
11
|
+
that date.
|
12
|
+
- Destroys resources with an internal `prov:invalidatedAtTime`.
|
13
|
+
- Adds conditional GET support.
|
14
|
+
- Handles RDFSource responses more efficiently, avoiding loading the
|
15
|
+
graph for HEAD & OPTIONS requests.
|
16
|
+
- More efficient update/delete with RDF::Transactions.
|
17
|
+
- Uses default prefixes from RDF.rb in responses.
|
1
18
|
|
2
19
|
0.3.0
|
3
20
|
------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/rdf/ldp/resource.rb
CHANGED
@@ -2,7 +2,7 @@ require 'link_header'
|
|
2
2
|
|
3
3
|
module RDF::LDP
|
4
4
|
##
|
5
|
-
# The base class for all LDP Resources.
|
5
|
+
# The base class for all LDP Resources.
|
6
6
|
#
|
7
7
|
# The internal state of a Resource is specific to a given persistent datastore
|
8
8
|
# (an `RDF::Repository` passed to the initilazer) and is managed through an
|
@@ -11,23 +11,23 @@ module RDF::LDP
|
|
11
11
|
# - a `#subject_uri` identifying the Resource.
|
12
12
|
# - a `#metagraph` containing server-internal properties of the Resource.
|
13
13
|
#
|
14
|
-
# Resources also define a basic set of CRUD operations, identity and current
|
15
|
-
# state, and a `#to_response`/`#each` method used by Rack & `Rack::LDP` to
|
16
|
-
# generate an appropriate HTTP response body.
|
14
|
+
# Resources also define a basic set of CRUD operations, identity and current
|
15
|
+
# state, and a `#to_response`/`#each` method used by Rack & `Rack::LDP` to
|
16
|
+
# generate an appropriate HTTP response body.
|
17
17
|
#
|
18
|
-
# `#metagraph' holds internal properites used by the server. It is distinct
|
19
|
-
# from, and may conflict with, other RDF and non-RDF information about the
|
20
|
-
# resource (e.g. representations suitable for a response body). Metagraph
|
21
|
-
# contains a canonical `rdf:type` statement, which specifies the resource's
|
22
|
-
# interaction model and a (dcterms:modified) last-modified date. If the
|
23
|
-
# resource is deleted, a (prov:invalidatedAt) flag in metagraph indicates
|
18
|
+
# `#metagraph' holds internal properites used by the server. It is distinct
|
19
|
+
# from, and may conflict with, other RDF and non-RDF information about the
|
20
|
+
# resource (e.g. representations suitable for a response body). Metagraph
|
21
|
+
# contains a canonical `rdf:type` statement, which specifies the resource's
|
22
|
+
# interaction model and a (dcterms:modified) last-modified date. If the
|
23
|
+
# resource is deleted, a (prov:invalidatedAt) flag in metagraph indicates
|
24
24
|
# this.
|
25
|
-
#
|
26
|
-
# The contents of `#metagraph` should not be confused with LDP
|
27
|
-
# server-managed-triples, Those triples are included in the state of the
|
25
|
+
#
|
26
|
+
# The contents of `#metagraph` should not be confused with LDP
|
27
|
+
# server-managed-triples, Those triples are included in the state of the
|
28
28
|
# resource as represented by the response body. `#metagraph` is invisible to
|
29
29
|
# the client except where a subclass mirrors its contents in the body.
|
30
|
-
#
|
30
|
+
#
|
31
31
|
# @example creating a new Resource
|
32
32
|
# repository = RDF::Repository.new
|
33
33
|
# resource = RDF::LDP::Resource.new('http://example.org/moomin', repository)
|
@@ -46,7 +46,7 @@ module RDF::LDP
|
|
46
46
|
# resource.update('blah', 'text/plain')
|
47
47
|
# resource.last_modified
|
48
48
|
# # => #<DateTime: 2015-10-25T14:32:04-07:00 ((2457321j,77524s,330658065n),-25200s,2299161j)>
|
49
|
-
#
|
49
|
+
#
|
50
50
|
# @example destroying a Resource
|
51
51
|
# resource.exists? # => true
|
52
52
|
# resource.destroyed? # => false
|
@@ -57,13 +57,13 @@ module RDF::LDP
|
|
57
57
|
# resource.destroyed? # => true
|
58
58
|
#
|
59
59
|
# Rack (via `RDF::LDP::Rack`) uses the `#request` method to dispatch requests and
|
60
|
-
# interpret responses. Disallowed HTTP methods result in
|
61
|
-
# `RDF::LDP::MethodNotAllowed`. Individual Resources populate `Link`, `Allow`,
|
62
|
-
# `ETag`, `Last-Modified`, and `Accept-*` headers as required by LDP. All
|
60
|
+
# interpret responses. Disallowed HTTP methods result in
|
61
|
+
# `RDF::LDP::MethodNotAllowed`. Individual Resources populate `Link`, `Allow`,
|
62
|
+
# `ETag`, `Last-Modified`, and `Accept-*` headers as required by LDP. All
|
63
63
|
# subclasses (MUST) return `self` as the Body, and respond to `#each`/
|
64
64
|
# `#respond_to` with the intended body.
|
65
65
|
#
|
66
|
-
# @example using HTTP request methods to get a Rack response
|
66
|
+
# @example using HTTP request methods to get a Rack response
|
67
67
|
# resource.request(:get, 200, {}, {})
|
68
68
|
# # => [200,
|
69
69
|
# {"Link"=>"<http://www.w3.org/ns/ldp#Resource>;rel=\"type\"",
|
@@ -81,7 +81,7 @@ module RDF::LDP
|
|
81
81
|
# resource.request(:put, 200, {}, {}) # RDF::LDP::MethodNotAllowed: put
|
82
82
|
#
|
83
83
|
# @see http://www.w3.org/TR/ldp/ for the Linked Data platform specification
|
84
|
-
# @see http://www.w3.org/TR/ldp/#dfn-linked-data-platform-resource for a
|
84
|
+
# @see http://www.w3.org/TR/ldp/#dfn-linked-data-platform-resource for a
|
85
85
|
# definition of 'Resource' in LDP
|
86
86
|
class Resource
|
87
87
|
# @!attribute [r] subject_uri
|
@@ -91,14 +91,14 @@ module RDF::LDP
|
|
91
91
|
# @!attribute [rw] metagraph
|
92
92
|
# a graph representing the server-internal state of the resource
|
93
93
|
attr_accessor :metagraph
|
94
|
-
|
94
|
+
|
95
95
|
class << self
|
96
96
|
##
|
97
|
-
# @return [RDF::URI] uri with lexical representation
|
97
|
+
# @return [RDF::URI] uri with lexical representation
|
98
98
|
# 'http://www.w3.org/ns/ldp#Resource'
|
99
99
|
#
|
100
100
|
# @see http://www.w3.org/TR/ldp/#dfn-linked-data-platform-resource
|
101
|
-
def to_uri
|
101
|
+
def to_uri
|
102
102
|
RDF::Vocab::LDP.Resource
|
103
103
|
end
|
104
104
|
|
@@ -113,41 +113,41 @@ module RDF::LDP
|
|
113
113
|
end
|
114
114
|
|
115
115
|
##
|
116
|
-
# Finds an existing resource and
|
117
|
-
#
|
116
|
+
# Finds an existing resource and
|
117
|
+
#
|
118
118
|
# @param [RDF::URI] uri the URI for the resource to be found
|
119
|
-
# @param [RDF::Repository] data a repostiory instance in which to find
|
119
|
+
# @param [RDF::Repository] data a repostiory instance in which to find
|
120
120
|
# the resource.
|
121
121
|
#
|
122
122
|
# @raise [RDF::LDP::NotFound] when the resource doesn't exist
|
123
123
|
#
|
124
124
|
# @return [RDF::LDP::Resource] a resource instance matching the given URI;
|
125
|
-
# usually of a subclass
|
125
|
+
# usually of a subclass
|
126
126
|
# from the interaction models.
|
127
127
|
def find(uri, data)
|
128
|
-
graph = RDF::Graph.new(uri
|
128
|
+
graph = RDF::Graph.new(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
|
132
132
|
klass = INTERACTION_MODELS[rdf_class.object] if rdf_class
|
133
133
|
klass ||= RDFSource
|
134
|
-
|
135
|
-
klass.new(uri, data)
|
134
|
+
|
135
|
+
klass.new(uri, data)
|
136
136
|
end
|
137
137
|
|
138
138
|
##
|
139
139
|
# Retrieves the correct interaction model from the Link headers.
|
140
140
|
#
|
141
141
|
# Headers are handled intelligently, e.g. if a client sends a request with
|
142
|
-
# Resource, RDFSource, and BasicContainer headers, the server gives a
|
143
|
-
# BasicContainer. An error is thrown if the headers contain conflicting
|
142
|
+
# Resource, RDFSource, and BasicContainer headers, the server gives a
|
143
|
+
# BasicContainer. An error is thrown if the headers contain conflicting
|
144
144
|
# types (i.e. NonRDFSource and another Resource class).
|
145
145
|
#
|
146
|
-
# @param [String] link_header a string containing Link headers from an
|
146
|
+
# @param [String] link_header a string containing Link headers from an
|
147
147
|
# HTTP request (Rack env)
|
148
|
-
#
|
149
|
-
# @return [Class] a subclass of {RDF::LDP::Resource} matching the
|
150
|
-
# requested interaction model;
|
148
|
+
#
|
149
|
+
# @return [Class] a subclass of {RDF::LDP::Resource} matching the
|
150
|
+
# requested interaction model;
|
151
151
|
def interaction_model(link_header)
|
152
152
|
models = LinkHeader.parse(link_header)
|
153
153
|
.links.select { |link| link['rel'].downcase == 'type' }
|
@@ -155,9 +155,9 @@ module RDF::LDP
|
|
155
155
|
|
156
156
|
return RDFSource if models.empty?
|
157
157
|
match = INTERACTION_MODELS.keys.reverse.find { |u| models.include? u }
|
158
|
-
|
158
|
+
|
159
159
|
if match == RDF::LDP::NonRDFSource.to_uri
|
160
|
-
raise NotAcceptable if
|
160
|
+
raise NotAcceptable if
|
161
161
|
models.include?(RDF::LDP::RDFSource.to_uri) ||
|
162
162
|
models.include?(RDF::LDP::Container.to_uri) ||
|
163
163
|
models.include?(RDF::LDP::DirectContainer.to_uri) ||
|
@@ -167,21 +167,29 @@ module RDF::LDP
|
|
167
167
|
|
168
168
|
INTERACTION_MODELS[match] || RDFSource
|
169
169
|
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# Build a graph name URI for the uri passed in
|
173
|
+
#
|
174
|
+
# @param uri [RDF::URI]
|
175
|
+
def metagraph_name(uri)
|
176
|
+
uri + '#meta'
|
177
|
+
end
|
170
178
|
end
|
171
179
|
|
172
180
|
##
|
173
181
|
# @param [RDF::URI, #to_s] subject_uri the uri that identifies the Resource
|
174
|
-
# @param [RDF::Repository] data the repository where the resource's RDF
|
175
|
-
# data (i.e. `metagraph`) is stored; defaults to an in-memory
|
182
|
+
# @param [RDF::Repository] data the repository where the resource's RDF
|
183
|
+
# data (i.e. `metagraph`) is stored; defaults to an in-memory
|
176
184
|
# RDF::Repository specific to this Resource.
|
177
185
|
#
|
178
186
|
# @yield [RDF::Resource] Gives itself to the block
|
179
187
|
#
|
180
|
-
# @example
|
188
|
+
# @example
|
181
189
|
# RDF::Resource.new('http://example.org/moomin')
|
182
190
|
#
|
183
191
|
# @example with a block
|
184
|
-
# RDF::Resource.new('http://example.org/moomin') do |resource|
|
192
|
+
# RDF::Resource.new('http://example.org/moomin') do |resource|
|
185
193
|
# resource.metagraph << RDF::Statement(...)
|
186
194
|
# end
|
187
195
|
#
|
@@ -195,10 +203,10 @@ module RDF::LDP
|
|
195
203
|
##
|
196
204
|
# @abstract creates the resource
|
197
205
|
#
|
198
|
-
# @param [IO, File] input input (usually from a Rack env's
|
206
|
+
# @param [IO, File] input input (usually from a Rack env's
|
199
207
|
# `rack.input` key) used to determine the Resource's initial state.
|
200
208
|
# @param [#to_s] content_type a MIME content_type used to interpret the
|
201
|
-
# input. This MAY be used as a content type for the created Resource
|
209
|
+
# input. This MAY be used as a content type for the created Resource
|
202
210
|
# (especially for `LDP::NonRDFSource`s).
|
203
211
|
#
|
204
212
|
# @yield gives a transaction (changeset) to collect changes to graph,
|
@@ -206,7 +214,7 @@ module RDF::LDP
|
|
206
214
|
# @yieldparam tx [RDF::Transaction]
|
207
215
|
# @return [RDF::LDP::Resource] self
|
208
216
|
#
|
209
|
-
# @raise [RDF::LDP::RequestError] when creation fails. May raise various
|
217
|
+
# @raise [RDF::LDP::RequestError] when creation fails. May raise various
|
210
218
|
# subclasses for the appropriate response codes.
|
211
219
|
# @raise [RDF::LDP::Conflict] when the resource exists
|
212
220
|
def create(input, content_type, &block)
|
@@ -224,7 +232,7 @@ module RDF::LDP
|
|
224
232
|
##
|
225
233
|
# @abstract update the resource
|
226
234
|
#
|
227
|
-
# @param [IO, File, #to_s] input input (usually from a Rack env's
|
235
|
+
# @param [IO, File, #to_s] input input (usually from a Rack env's
|
228
236
|
# `rack.input` key) used to determine the Resource's new state.
|
229
237
|
# @param [#to_s] content_type a MIME content_type used to interpret the
|
230
238
|
# input.
|
@@ -234,7 +242,7 @@ module RDF::LDP
|
|
234
242
|
# @yieldparam tx [RDF::Transaction]
|
235
243
|
# @return [RDF::LDP::Resource] self
|
236
244
|
#
|
237
|
-
# @raise [RDF::LDP::RequestError] when update fails. May raise various
|
245
|
+
# @raise [RDF::LDP::RequestError] when update fails. May raise various
|
238
246
|
# subclasses for the appropriate response codes.
|
239
247
|
def update(input, content_type, &block)
|
240
248
|
return create(input, content_type, &block) unless exists?
|
@@ -248,20 +256,20 @@ module RDF::LDP
|
|
248
256
|
##
|
249
257
|
# Mark the resource as destroyed.
|
250
258
|
#
|
251
|
-
# This adds a statment to the metagraph expressing that the resource has
|
259
|
+
# This adds a statment to the metagraph expressing that the resource has
|
252
260
|
# been deleted
|
253
261
|
#
|
254
262
|
# @yield gives a transaction (changeset) to collect changes to graph,
|
255
263
|
# metagraph and other resources' (e.g. containers) graphs
|
256
264
|
# @yieldparam tx [RDF::Transaction]
|
257
265
|
# @return [RDF::LDP::Resource] self
|
258
|
-
#
|
259
|
-
# @todo Use of owl:Nothing is probably problematic. Define an internal
|
266
|
+
#
|
267
|
+
# @todo Use of owl:Nothing is probably problematic. Define an internal
|
260
268
|
# namespace and class represeting deletion status as a stateful property.
|
261
269
|
def destroy(&block)
|
262
270
|
@data.transaction do |transaction|
|
263
271
|
containers.each { |c| c.remove(self, transaction) if c.container? }
|
264
|
-
transaction << RDF::Statement(subject_uri,
|
272
|
+
transaction << RDF::Statement(subject_uri,
|
265
273
|
RDF::Vocab::PROV.invalidatedAtTime,
|
266
274
|
DateTime.now,
|
267
275
|
graph_name: metagraph_name)
|
@@ -273,8 +281,8 @@ module RDF::LDP
|
|
273
281
|
##
|
274
282
|
# Gives the status of the resource's existance.
|
275
283
|
#
|
276
|
-
# @note destroyed resources continue to exist in the sense represeted by
|
277
|
-
# this method.
|
284
|
+
# @note destroyed resources continue to exist in the sense represeted by
|
285
|
+
# this method.
|
278
286
|
#
|
279
287
|
# @return [Boolean] true if the resource exists within the repository
|
280
288
|
def exists?
|
@@ -291,14 +299,14 @@ module RDF::LDP
|
|
291
299
|
##
|
292
300
|
# Returns an Etag. This may be a strong or a weak ETag.
|
293
301
|
#
|
294
|
-
# @return [String] an HTTP Etag
|
302
|
+
# @return [String] an HTTP Etag
|
295
303
|
#
|
296
304
|
# @note these etags are strong if (and only if) all software that updates
|
297
305
|
# the resource also updates the ETag
|
298
306
|
#
|
299
307
|
# @see http://www.w3.org/TR/ldp#h-ldpr-gen-etags LDP ETag clause for GET
|
300
308
|
# @see http://www.w3.org/TR/ldp#h-ldpr-put-precond LDP ETag clause for PUT
|
301
|
-
# @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.3
|
309
|
+
# @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.3
|
302
310
|
# description of strong vs. weak validators
|
303
311
|
def etag
|
304
312
|
return nil unless exists?
|
@@ -306,13 +314,21 @@ module RDF::LDP
|
|
306
314
|
end
|
307
315
|
|
308
316
|
##
|
309
|
-
# @return [DateTime] the time this resource was last modified
|
317
|
+
# @return [DateTime] the time this resource was last modified; `nil` if the
|
318
|
+
# resource doesn't exist and has no modified date
|
319
|
+
# @raise [RDF::LDP::RequestError] when the resource exists but is missing a
|
320
|
+
# `last_modified'
|
310
321
|
#
|
311
322
|
# @todo handle cases where there is more than one RDF::DC.modified.
|
312
323
|
# check for the most recent date
|
313
324
|
def last_modified
|
314
325
|
results = @metagraph.query([subject_uri, RDF::Vocab::DC.modified, :time])
|
315
|
-
|
326
|
+
|
327
|
+
if results.empty?
|
328
|
+
return nil unless exists?
|
329
|
+
raise(RequestError, "Missing dc:modified date for #{subject_uri}")
|
330
|
+
end
|
331
|
+
|
316
332
|
results.first.object.object
|
317
333
|
end
|
318
334
|
|
@@ -320,7 +336,7 @@ module RDF::LDP
|
|
320
336
|
# @param [String] tag a tag to compare to `#etag`
|
321
337
|
# @return [Boolean] whether the given tag matches `#etag`
|
322
338
|
def match?(tag)
|
323
|
-
tag == etag
|
339
|
+
tag == etag
|
324
340
|
end
|
325
341
|
|
326
342
|
##
|
@@ -332,7 +348,7 @@ module RDF::LDP
|
|
332
348
|
##
|
333
349
|
# @return [Array<Symbol>] a list of HTTP methods allowed by this resource.
|
334
350
|
def allowed_methods
|
335
|
-
[:GET, :POST, :PUT, :DELETE, :PATCH, :OPTIONS, :HEAD].select do |m|
|
351
|
+
[:GET, :POST, :PUT, :DELETE, :PATCH, :OPTIONS, :HEAD].select do |m|
|
336
352
|
respond_to?(m.downcase, true)
|
337
353
|
end
|
338
354
|
end
|
@@ -370,10 +386,10 @@ module RDF::LDP
|
|
370
386
|
end
|
371
387
|
|
372
388
|
##
|
373
|
-
# Runs the request and returns the object's desired HTTP response body,
|
374
|
-
# conforming to the Rack interfare.
|
389
|
+
# Runs the request and returns the object's desired HTTP response body,
|
390
|
+
# conforming to the Rack interfare.
|
375
391
|
#
|
376
|
-
# @see http://www.rubydoc.info/github/rack/rack/master/file/SPEC#The_Body
|
392
|
+
# @see http://www.rubydoc.info/github/rack/rack/master/file/SPEC#The_Body
|
377
393
|
# for Rack body documentation
|
378
394
|
def to_response
|
379
395
|
[]
|
@@ -382,55 +398,55 @@ module RDF::LDP
|
|
382
398
|
|
383
399
|
##
|
384
400
|
# Build the response for the HTTP `method` given.
|
385
|
-
#
|
401
|
+
#
|
386
402
|
# The method passed in is symbolized, downcased, and sent to `self` with the
|
387
403
|
# other three parameters.
|
388
404
|
#
|
389
405
|
# Request methods are expected to return an Array appropriate for a Rack
|
390
|
-
# response; to return this object (e.g. for a sucessful GET) the response
|
406
|
+
# response; to return this object (e.g. for a sucessful GET) the response
|
391
407
|
# may be `[status, headers, self]`.
|
392
408
|
#
|
393
|
-
# If the method given is unimplemented, we understand it to require an HTTP
|
409
|
+
# If the method given is unimplemented, we understand it to require an HTTP
|
394
410
|
# 405 response, and throw the appropriate error.
|
395
411
|
#
|
396
|
-
# @param [#to_sym] method the HTTP request method of the response; this
|
412
|
+
# @param [#to_sym] method the HTTP request method of the response; this
|
397
413
|
# message will be downcased and sent to the object.
|
398
|
-
# @param [Fixnum] status an HTTP response code; this status should be sent
|
414
|
+
# @param [Fixnum] status an HTTP response code; this status should be sent
|
399
415
|
# back to the caller or altered, as appropriate.
|
400
|
-
# @param [Hash<String, String>] headers a hash mapping HTTP headers
|
401
|
-
# built for the response to their contents; these headers should be sent
|
416
|
+
# @param [Hash<String, String>] headers a hash mapping HTTP headers
|
417
|
+
# built for the response to their contents; these headers should be sent
|
402
418
|
# back to the caller or altered, as appropriate.
|
403
419
|
# @param [Hash] env the Rack env for the request
|
404
420
|
#
|
405
|
-
# @return [Array<Fixnum, Hash<String, String>, #each] a new Rack response
|
421
|
+
# @return [Array<Fixnum, Hash<String, String>, #each] a new Rack response
|
406
422
|
# array.
|
407
423
|
def request(method, status, headers, env)
|
408
424
|
raise Gone if destroyed?
|
409
425
|
begin
|
410
426
|
send(method.to_sym.downcase, status, headers, env)
|
411
427
|
rescue NotImplementedError => e
|
412
|
-
raise MethodNotAllowed, method
|
428
|
+
raise MethodNotAllowed, method
|
413
429
|
end
|
414
430
|
end
|
415
431
|
|
416
432
|
private
|
417
433
|
|
418
434
|
##
|
419
|
-
# Generate response for GET requests. Returns existing status and headers,
|
435
|
+
# Generate response for GET requests. Returns existing status and headers,
|
420
436
|
# with `self` as the body.
|
421
437
|
def get(status, headers, env)
|
422
438
|
[status, update_headers(headers), self]
|
423
439
|
end
|
424
440
|
|
425
441
|
##
|
426
|
-
# Generate response for HEAD requsets. Adds appropriate headers and returns
|
442
|
+
# Generate response for HEAD requsets. Adds appropriate headers and returns
|
427
443
|
# an empty body.
|
428
444
|
def head(status, headers, env)
|
429
445
|
[status, update_headers(headers), []]
|
430
446
|
end
|
431
447
|
|
432
448
|
##
|
433
|
-
# Generate response for OPTIONS requsets. Adds appropriate headers and
|
449
|
+
# Generate response for OPTIONS requsets. Adds appropriate headers and
|
434
450
|
# returns an empty body.
|
435
451
|
def options(status, headers, env)
|
436
452
|
[status, update_headers(headers), []]
|
@@ -475,16 +491,16 @@ module RDF::LDP
|
|
475
491
|
##
|
476
492
|
# @return [RDF::URI] the name for this resource's metagraph
|
477
493
|
def metagraph_name
|
478
|
-
subject_uri
|
494
|
+
self.class.metagraph_name(subject_uri)
|
479
495
|
end
|
480
496
|
|
481
497
|
##
|
482
498
|
# @param [Hash<String, String>] headers
|
483
499
|
# @return [Hash<String, String>] the updated headers
|
484
500
|
def update_headers(headers)
|
485
|
-
headers['Link'] =
|
501
|
+
headers['Link'] =
|
486
502
|
([headers['Link']] + link_headers).compact.join(",")
|
487
|
-
|
503
|
+
|
488
504
|
headers['Allow'] = allowed_methods.join(', ')
|
489
505
|
headers['Accept-Post'] = accept_post if respond_to?(:post, true)
|
490
506
|
headers['Accept-Patch'] = accept_patch if respond_to?(:patch, true)
|
@@ -511,7 +527,7 @@ module RDF::LDP
|
|
511
527
|
end
|
512
528
|
|
513
529
|
##
|
514
|
-
# @return [Array<String>] an array of link headers to add to the
|
530
|
+
# @return [Array<String>] an array of link headers to add to the
|
515
531
|
# existing ones
|
516
532
|
#
|
517
533
|
# @see http://www.w3.org/TR/ldp/#h-ldpr-gen-linktypehdr
|
@@ -542,25 +558,25 @@ module RDF::LDP
|
|
542
558
|
# ask the Repository for the current last_modified to delete the statement
|
543
559
|
# transactionally
|
544
560
|
modified = last_modified
|
545
|
-
transaction.delete RDF::Statement(subject_uri,
|
546
|
-
RDF::Vocab::DC.modified,
|
561
|
+
transaction.delete RDF::Statement(subject_uri,
|
562
|
+
RDF::Vocab::DC.modified,
|
547
563
|
modified,
|
548
564
|
graph_name: metagraph_name) if modified
|
549
565
|
|
550
|
-
transaction.insert RDF::Statement(subject_uri,
|
551
|
-
RDF::Vocab::DC.modified,
|
566
|
+
transaction.insert RDF::Statement(subject_uri,
|
567
|
+
RDF::Vocab::DC.modified,
|
552
568
|
DateTime.now,
|
553
569
|
graph_name: metagraph_name)
|
554
570
|
else
|
555
571
|
metagraph.update([subject_uri, RDF::Vocab::DC.modified, DateTime.now])
|
556
|
-
end
|
572
|
+
end
|
557
573
|
end
|
558
574
|
|
559
575
|
##
|
560
576
|
# Sets the last modified date/time to the URI for this resource's class
|
561
577
|
def set_interaction_model(transaction)
|
562
|
-
transaction.insert(RDF::Statement(subject_uri,
|
563
|
-
RDF.type,
|
578
|
+
transaction.insert(RDF::Statement(subject_uri,
|
579
|
+
RDF.type,
|
564
580
|
self.class.to_uri,
|
565
581
|
graph_name: metagraph.graph_name))
|
566
582
|
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.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|