rdf-ldp 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/VERSION +1 -1
- data/lib/rdf/ldp.rb +7 -14
- data/lib/rdf/ldp/interaction_model.rb +87 -0
- data/lib/rdf/ldp/resource.rb +12 -18
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 608eab3122c07390b9ea22a578ab0744fe18fe02
|
4
|
+
data.tar.gz: ddcd8b00538a683ef78f4cbda395573cebacdc23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29b2ba9c4f2f3baab28bc2d554f5e782cc3756fad291e277486c393e54166a11ccd3ce331c1de11c46849da36548df9ba3a092abbd8424989ee98e9bfb77a57d
|
7
|
+
data.tar.gz: 2e52d0ea153620570b1be88497ff0edb1be04ac860715280e69c9389d01361614c8a39b7d26337007985a8b13d97f546a4d4384fa90f7eb850c5c3e49100aa55
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
data/lib/rdf/ldp.rb
CHANGED
@@ -9,6 +9,7 @@ require 'rdf/ldp/non_rdf_source'
|
|
9
9
|
require 'rdf/ldp/container'
|
10
10
|
require 'rdf/ldp/direct_container'
|
11
11
|
require 'rdf/ldp/indirect_container'
|
12
|
+
require 'rdf/ldp/interaction_model'
|
12
13
|
|
13
14
|
module RDF
|
14
15
|
##
|
@@ -20,20 +21,12 @@ module RDF
|
|
20
21
|
# @see RDF::LDP::Resource
|
21
22
|
# @see http://www.w3.org/TR/ldp/ for the Linked Data platform specification
|
22
23
|
module LDP
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
RDF::LDP::RDFSource.to_uri => RDF::LDP::RDFSource,
|
30
|
-
RDF::LDP::Container.to_uri => RDF::LDP::Container,
|
31
|
-
RDF::Vocab::LDP.BasicContainer => RDF::LDP::Container,
|
32
|
-
RDF::LDP::DirectContainer.to_uri => RDF::LDP::DirectContainer,
|
33
|
-
RDF::LDP::IndirectContainer.to_uri => RDF::LDP::IndirectContainer,
|
34
|
-
RDF::LDP::NonRDFSource.to_uri => RDF::LDP::NonRDFSource
|
35
|
-
}.freeze
|
36
|
-
|
24
|
+
InteractionModel.register(RDF::LDP::RDFSource, default: true)
|
25
|
+
InteractionModel.register(RDF::LDP::Container, for: RDF::Vocab::LDP.BasicContainer)
|
26
|
+
InteractionModel.register(RDF::LDP::DirectContainer)
|
27
|
+
InteractionModel.register(RDF::LDP::IndirectContainer)
|
28
|
+
InteractionModel.register(RDF::LDP::NonRDFSource)
|
29
|
+
|
37
30
|
CONTAINER_CLASSES = {
|
38
31
|
basic: RDF::Vocab::LDP.BasicContainer.freeze,
|
39
32
|
direct: RDF::LDP::DirectContainer.to_uri.freeze,
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module RDF
|
2
|
+
module LDP
|
3
|
+
class InteractionModel
|
4
|
+
class << self
|
5
|
+
##
|
6
|
+
# Interaction models are in reverse order of preference for POST/PUT
|
7
|
+
# requests; e.g. if a client sends a request with Resource, RDFSource, and
|
8
|
+
# BasicContainer headers, the server gives a basic container.
|
9
|
+
#
|
10
|
+
# Interaction models are initialized in the correct order, but with no classed
|
11
|
+
# registered to handle them.
|
12
|
+
@@interaction_models = {
|
13
|
+
RDF::LDP::RDFSource.to_uri => nil,
|
14
|
+
RDF::LDP::Container.to_uri => nil,
|
15
|
+
RDF::Vocab::LDP.BasicContainer => nil,
|
16
|
+
RDF::LDP::DirectContainer.to_uri => nil,
|
17
|
+
RDF::LDP::IndirectContainer.to_uri => nil,
|
18
|
+
RDF::LDP::NonRDFSource.to_uri => nil
|
19
|
+
}
|
20
|
+
|
21
|
+
##
|
22
|
+
# Register a new interaction model for one or more Link header URIs. klass.to_uri
|
23
|
+
# will automatically be registered.
|
24
|
+
#
|
25
|
+
# @param [RDF::LDP::Resource] klass the implementation class to register
|
26
|
+
# @param [Hash <Symbol, *>] opts registration options:
|
27
|
+
# :default [true, false] if true, klass will become the new default klass for
|
28
|
+
# unrecognized Link headers
|
29
|
+
# :for [RDF::URI, Array<RDF::URI>] additional URIs for which klass should become
|
30
|
+
# the interaction model
|
31
|
+
#
|
32
|
+
# @return [RDF::LDP::Resource] klass
|
33
|
+
def register(klass, opts={})
|
34
|
+
unless klass.ancestors.include?(RDF::LDP::Resource)
|
35
|
+
raise ArgumentError, "Interaction models must subclass `RDF::LDP::Resource`"
|
36
|
+
end
|
37
|
+
@@default = klass if opts[:default] or @@default.nil?
|
38
|
+
@@interaction_models[klass.to_uri] = klass
|
39
|
+
Array(opts[:for]).each do |model|
|
40
|
+
@@interaction_models[model] = klass
|
41
|
+
end
|
42
|
+
klass
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Find the appropriate interaction model given a set of Link header URIs.
|
47
|
+
#
|
48
|
+
# @param [Array<RDF::URI>] uris
|
49
|
+
#
|
50
|
+
# @return [Class] a subclass of {RDF::LDP::Resource} that most narrowly matches the
|
51
|
+
# supplied `uris`, or the default interaction model if nothing matches
|
52
|
+
def find(uris)
|
53
|
+
match = @@interaction_models.keys.reverse.find { |u| uris.include? u }
|
54
|
+
self.for(match) || @@default
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Find the interaction model registered for a given uri
|
59
|
+
#
|
60
|
+
# @param [RDF::URI] uri
|
61
|
+
#
|
62
|
+
# @return [Class] the {RDF::LDP::Resource} subclass registered to `uri`
|
63
|
+
def for(uri)
|
64
|
+
@@interaction_models[uri]
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# The default registered interaction model
|
69
|
+
def default
|
70
|
+
@@default
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Test an array of URIs to see if their interaction models are compatible (e.g., all of the URIs
|
75
|
+
# refer either to RDF models or non-RDF models, but not a combination of both).
|
76
|
+
#
|
77
|
+
# @param [Array<RDF::URI>] uris
|
78
|
+
# @return [TrueClass or FalseClass] true if the models specified by `uris` are compatible
|
79
|
+
def compatible?(uris)
|
80
|
+
classes = uris.collect { |m| self.for(m) }
|
81
|
+
(rdf,non_rdf) = classes.compact.partition { |c| c.ancestors.include?(RDFSource) }
|
82
|
+
rdf.empty? or non_rdf.empty?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/rdf/ldp/resource.rb
CHANGED
@@ -132,8 +132,10 @@ module RDF::LDP
|
|
132
132
|
graph = RDF::Graph.new(graph_name: metagraph_name(uri), data: data)
|
133
133
|
raise NotFound if graph.empty?
|
134
134
|
|
135
|
-
|
136
|
-
|
135
|
+
klass = graph.query([uri, RDF.type, :o]).find do |rdf_class|
|
136
|
+
candidate = InteractionModel.for(rdf_class.object)
|
137
|
+
break candidate unless candidate.nil?
|
138
|
+
end
|
137
139
|
klass ||= RDFSource
|
138
140
|
|
139
141
|
klass.new(uri, data)
|
@@ -156,21 +158,13 @@ module RDF::LDP
|
|
156
158
|
models =
|
157
159
|
LinkHeader.parse(link_header)
|
158
160
|
.links.select { |link| link['rel'].casecmp 'type' }
|
159
|
-
.map { |link| link.href }
|
160
|
-
|
161
|
-
return
|
162
|
-
|
163
|
-
|
164
|
-
if match == RDF::LDP::NonRDFSource.to_uri
|
165
|
-
raise NotAcceptable if
|
166
|
-
models.include?(RDF::LDP::RDFSource.to_uri) ||
|
167
|
-
models.include?(RDF::LDP::Container.to_uri) ||
|
168
|
-
models.include?(RDF::LDP::DirectContainer.to_uri) ||
|
169
|
-
models.include?(RDF::LDP::IndirectContainer.to_uri) ||
|
170
|
-
models.include?(RDF::URI('http://www.w3.org/ns/ldp#BasicContainer'))
|
171
|
-
end
|
161
|
+
.map { |link| RDF::URI.intern(link.href) }
|
162
|
+
|
163
|
+
return InteractionModel.default if models.empty?
|
164
|
+
|
165
|
+
raise NotAcceptable unless InteractionModel.compatible?(models)
|
172
166
|
|
173
|
-
|
167
|
+
InteractionModel.find(models)
|
174
168
|
end
|
175
169
|
|
176
170
|
##
|
@@ -199,7 +193,7 @@ module RDF::LDP
|
|
199
193
|
# end
|
200
194
|
#
|
201
195
|
def initialize(subject_uri, data = RDF::Repository.new)
|
202
|
-
@subject_uri = RDF::URI(subject_uri)
|
196
|
+
@subject_uri = RDF::URI.intern(subject_uri)
|
203
197
|
@data = data
|
204
198
|
@metagraph = RDF::Graph.new(graph_name: metagraph_name, data: data)
|
205
199
|
yield self if block_given?
|
@@ -585,7 +579,7 @@ module RDF::LDP
|
|
585
579
|
end
|
586
580
|
|
587
581
|
##
|
588
|
-
# Sets the
|
582
|
+
# Sets the interaction model to the URI for this resource's class
|
589
583
|
def set_interaction_model(transaction)
|
590
584
|
transaction.insert(RDF::Statement(subject_uri,
|
591
585
|
RDF.type,
|
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.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -360,6 +360,7 @@ files:
|
|
360
360
|
- lib/rdf/ldp/container.rb
|
361
361
|
- lib/rdf/ldp/direct_container.rb
|
362
362
|
- lib/rdf/ldp/indirect_container.rb
|
363
|
+
- lib/rdf/ldp/interaction_model.rb
|
363
364
|
- lib/rdf/ldp/non_rdf_source.rb
|
364
365
|
- lib/rdf/ldp/rdf_source.rb
|
365
366
|
- lib/rdf/ldp/resource.rb
|
@@ -386,7 +387,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
386
387
|
version: '0'
|
387
388
|
requirements: []
|
388
389
|
rubyforge_project:
|
389
|
-
rubygems_version: 2.
|
390
|
+
rubygems_version: 2.6.8
|
390
391
|
signing_key:
|
391
392
|
specification_version: 4
|
392
393
|
summary: A suite of LDP software and middleware for RDF.rb.
|