tripod 0.9.11 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tripod/attributes.rb +2 -3
- data/lib/tripod/criteria.rb +10 -3
- data/lib/tripod/fields.rb +13 -1
- data/lib/tripod/finders.rb +14 -3
- data/lib/tripod/sparql_client.rb +0 -26
- data/lib/tripod/version.rb +1 -1
- data/spec/spec_helper.rb +7 -3
- data/spec/tripod/criteria_spec.rb +31 -10
- data/spec/tripod/fields_spec.rb +11 -1
- data/spec/tripod/finders_spec.rb +6 -5
- metadata +3 -5
- data/spec/tripod/sparql_client_spec.rb +0 -128
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc6eabb51253efb188e06ee368e07a0a889e3879
|
4
|
+
data.tar.gz: c714ca5b1320c2fd26669951cc318b0c89a27cb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2adbfe9b6a9bcb9dae25e1550c06db0d249dc99ce9e00cf27b6923402f4fddc9eb8f0da52a75f69e115a64950c1b0efdeb4e4bb3925182de78ea6263048bd2e3
|
7
|
+
data.tar.gz: 0485201ce47c65d4db7470f4c5ffe3603aa545cd730cbd154de1293ff736f36eab86ec5c1c90752fada3acfb0e86350ef6c1419a4c3c7374305704df24b692fe
|
data/lib/tripod/attributes.rb
CHANGED
@@ -20,8 +20,7 @@ module Tripod::Attributes
|
|
20
20
|
#
|
21
21
|
# @return Native Ruby object (e.g. String, DateTime) or array of them, depending on whether the field is multivalued or not
|
22
22
|
def read_attribute(name, field=nil)
|
23
|
-
field ||= self.
|
24
|
-
raise Tripod::Errors::FieldNotPresent.new unless field
|
23
|
+
field ||= self.class.get_field(name)
|
25
24
|
|
26
25
|
attr_values = read_predicate(field.predicate)
|
27
26
|
|
@@ -88,4 +87,4 @@ module Tripod::Attributes
|
|
88
87
|
value
|
89
88
|
end
|
90
89
|
end
|
91
|
-
end
|
90
|
+
end
|
data/lib/tripod/criteria.rb
CHANGED
@@ -41,9 +41,16 @@ module Tripod
|
|
41
41
|
# Note: the subject being returned by the query must be identified by ?uri
|
42
42
|
# e.g. my_criteria.where("?uri a <http://my-type>")
|
43
43
|
#
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def where(filter)
|
45
|
+
if filter.is_a?(String) # we gotta Sparql snippet
|
46
|
+
where_clauses << filter
|
47
|
+
elsif filter.is_a?(Hash)
|
48
|
+
filter.each_pair do |key, value|
|
49
|
+
field = resource_class.get_field(key)
|
50
|
+
value = RDF::Literal.new(value) unless value.respond_to?(:to_base)
|
51
|
+
where_clauses << "?uri <#{ field.predicate }> #{ value.to_base }"
|
52
|
+
end
|
53
|
+
end
|
47
54
|
self
|
48
55
|
end
|
49
56
|
|
data/lib/tripod/fields.rb
CHANGED
@@ -41,6 +41,18 @@ module Tripod::Fields
|
|
41
41
|
add_field(name, predicate, options)
|
42
42
|
end
|
43
43
|
|
44
|
+
# Return the field object on a +Resource+ associated with the given name.
|
45
|
+
#
|
46
|
+
# @example Get the field.
|
47
|
+
# Person.get_field(:name)
|
48
|
+
#
|
49
|
+
# @param [ Symbol ] name The name of the field.
|
50
|
+
def get_field(name)
|
51
|
+
field = self.fields[name]
|
52
|
+
raise Tripod::Errors::FieldNotPresent.new unless field
|
53
|
+
field
|
54
|
+
end
|
55
|
+
|
44
56
|
protected
|
45
57
|
|
46
58
|
# Define a field attribute for the +Resource+.
|
@@ -153,4 +165,4 @@ module Tripod::Fields
|
|
153
165
|
Tripod::Fields::Standard.new(name, predicate, options)
|
154
166
|
end
|
155
167
|
end
|
156
|
-
end
|
168
|
+
end
|
data/lib/tripod/finders.rb
CHANGED
@@ -109,7 +109,7 @@ module Tripod::Finders
|
|
109
109
|
uris_sparql_str = uris.map{ |u| "<#{u.to_s}>" }.join(" ")
|
110
110
|
|
111
111
|
# Do a big describe statement, and read the results into an in-memory repo
|
112
|
-
ntriples_string = Tripod::SparqlClient::Query.query("
|
112
|
+
ntriples_string = Tripod::SparqlClient::Query.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . VALUES ?s { #{uris_sparql_str} } }", "application/n-triples")
|
113
113
|
graph = _rdf_graph_from_ntriples_string(ntriples_string, graph)
|
114
114
|
end
|
115
115
|
|
@@ -171,7 +171,18 @@ module Tripod::Finders
|
|
171
171
|
# @option options [ String ] uri_variable The name of the uri variable in the query, if not 'uri'
|
172
172
|
def _describe_query_for_select(select_sparql, opts={})
|
173
173
|
uri_variable = opts[:uri_variable] || "uri"
|
174
|
-
"
|
174
|
+
"
|
175
|
+
CONSTRUCT { ?tripod_construct_s ?tripod_construct_p ?tripod_construct_o }
|
176
|
+
WHERE {
|
177
|
+
?tripod_construct_s ?tripod_construct_p ?tripod_construct_o .
|
178
|
+
{
|
179
|
+
SELECT (?#{uri_variable} as ?tripod_construct_s)
|
180
|
+
{
|
181
|
+
#{select_sparql}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
"
|
175
186
|
end
|
176
187
|
|
177
188
|
# For a select query, get a raw serialisation of the DESCRIPTION of the resources from the database.
|
@@ -238,4 +249,4 @@ module Tripod::Finders
|
|
238
249
|
end
|
239
250
|
|
240
251
|
end
|
241
|
-
end
|
252
|
+
end
|
data/lib/tripod/sparql_client.rb
CHANGED
@@ -97,30 +97,4 @@ module Tripod::SparqlClient
|
|
97
97
|
|
98
98
|
end
|
99
99
|
|
100
|
-
module Data
|
101
|
-
class DataClient
|
102
|
-
def self.submit(graph_uri, data, method)
|
103
|
-
url = "#{Tripod.data_endpoint}?graph=#{graph_uri}"
|
104
|
-
begin
|
105
|
-
RestClient::Request.execute(
|
106
|
-
:method => method,
|
107
|
-
:url => url,
|
108
|
-
:timeout => Tripod.timeout_seconds,
|
109
|
-
:payload => data
|
110
|
-
)
|
111
|
-
true
|
112
|
-
rescue RestClient::BadRequest => e
|
113
|
-
raise Tripod::Errors::BadDataRequest.new(e.http_body, e)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def self.append(graph_uri, data)
|
119
|
-
DataClient.submit(graph_uri, data, :post)
|
120
|
-
end
|
121
|
-
|
122
|
-
def self.replace(graph_uri, data)
|
123
|
-
DataClient.submit(graph_uri, data, :put)
|
124
|
-
end
|
125
|
-
end
|
126
100
|
end
|
data/lib/tripod/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -28,9 +28,13 @@ end
|
|
28
28
|
|
29
29
|
# configure any settings for testing...
|
30
30
|
Tripod.configure do |config|
|
31
|
-
config.update_endpoint = 'http://127.0.0.1:3030/tripod-test/update'
|
32
|
-
config.query_endpoint = 'http://127.0.0.1:3030/tripod-test/sparql'
|
33
|
-
config.data_endpoint = 'http://127.0.0.1:3030/tripod-test/data'
|
31
|
+
# config.update_endpoint = 'http://127.0.0.1:3030/tripod-test/update'
|
32
|
+
# config.query_endpoint = 'http://127.0.0.1:3030/tripod-test/sparql'
|
33
|
+
# config.data_endpoint = 'http://127.0.0.1:3030/tripod-test/data'
|
34
|
+
|
35
|
+
config.update_endpoint = 'http://127.0.0.1:3002/sparql/raw/update'
|
36
|
+
config.query_endpoint = 'http://127.0.0.1:3002/sparql/raw'
|
37
|
+
#config.data_endpoint = 'http://127.0.0.1:3030/tripod-test/data'
|
34
38
|
end
|
35
39
|
|
36
40
|
# Autoload every model for the test suite that sits in spec/app/models.
|
@@ -31,19 +31,40 @@ describe Tripod::Criteria do
|
|
31
31
|
|
32
32
|
describe "#where" do
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
context 'given a string' do
|
35
|
+
it "should add the sparql snippet to the where clauses" do
|
36
|
+
resource_criteria.where("blah")
|
37
|
+
resource_criteria.where_clauses.should == ["?uri ?p ?o", "blah"]
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
it "should return an instance of Criteria" do
|
41
|
+
resource_criteria.where("blah").class == Tripod::Criteria
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
it "should return an instance of Criteria with the where clauses added" do
|
45
|
+
resource_criteria.where("blah").where_clauses.should == ["?uri ?p ?o", "blah"]
|
46
|
+
end
|
45
47
|
end
|
46
48
|
|
49
|
+
context 'given a hash' do
|
50
|
+
context 'with a native Ruby value' do
|
51
|
+
let(:value) { 'blah' }
|
52
|
+
|
53
|
+
it 'should construct a sparql snippet with the appropriate predicate, treating the value as a literal' do
|
54
|
+
criteria = resource_criteria.where(label: value)
|
55
|
+
criteria.where_clauses[1].should == "?uri <#{ RDF::RDFS.label }> \"#{ value }\""
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with a native RDF value' do
|
60
|
+
let(:value) { RDF::URI.new('http://example.com/bob') }
|
61
|
+
|
62
|
+
it 'should construct a sparql snippet with the appropriate predicate' do
|
63
|
+
criteria = resource_criteria.where(label: value)
|
64
|
+
criteria.where_clauses[1].should == "?uri <#{ RDF::RDFS.label }> <#{ value.to_s }>"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
47
68
|
end
|
48
69
|
|
49
70
|
describe "#extras" do
|
@@ -114,4 +135,4 @@ describe Tripod::Criteria do
|
|
114
135
|
end
|
115
136
|
end
|
116
137
|
|
117
|
-
end
|
138
|
+
end
|
data/spec/tripod/fields_spec.rb
CHANGED
@@ -39,4 +39,14 @@ describe Tripod::Fields do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
|
+
describe '.get_field' do
|
44
|
+
it 'should raise an error if the field does not exist' do
|
45
|
+
expect { Person.send(:get_field, :shoe_size) }.to raise_error(Tripod::Errors::FieldNotPresent)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should return the field for the given name' do
|
49
|
+
Person.send(:get_field, :age).name.should == :age
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/tripod/finders_spec.rb
CHANGED
@@ -190,7 +190,7 @@ describe Tripod::Finders do
|
|
190
190
|
end
|
191
191
|
|
192
192
|
it 'should return the first resources of this type' do
|
193
|
-
Person.first.should ==
|
193
|
+
Person.first.should == bill
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
@@ -205,11 +205,12 @@ describe Tripod::Finders do
|
|
205
205
|
it 'returns an array of resources which match those in the db' do
|
206
206
|
res = Person.find_by_sparql('SELECT ?uri ?graph WHERE { GRAPH ?graph { ?uri ?p ?o } }')
|
207
207
|
res.length.should == 2
|
208
|
-
res.first.should ==
|
209
|
-
res.last.should ==
|
208
|
+
res.first.should == bill
|
209
|
+
res.last.should == ric
|
210
210
|
|
211
|
-
res.
|
212
|
-
|
211
|
+
r = res.last
|
212
|
+
r.name.should == "ric"
|
213
|
+
r.knows.should == [RDF::URI.new("http://example.com/id/bill")]
|
213
214
|
end
|
214
215
|
|
215
216
|
it 'uses the uri and graph variables if supplied' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tripod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ric Roberts
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -255,7 +255,6 @@ files:
|
|
255
255
|
- spec/tripod/repository_spec.rb
|
256
256
|
- spec/tripod/resource_spec.rb
|
257
257
|
- spec/tripod/serialization_spec.rb
|
258
|
-
- spec/tripod/sparql_client_spec.rb
|
259
258
|
- spec/tripod/sparql_query_spec.rb
|
260
259
|
- spec/tripod/state_spec.rb
|
261
260
|
- spec/tripod/streaming_spec.rb
|
@@ -280,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
279
|
version: 1.3.6
|
281
280
|
requirements: []
|
282
281
|
rubyforge_project: tripod
|
283
|
-
rubygems_version: 2.2.
|
282
|
+
rubygems_version: 2.2.2
|
284
283
|
signing_key:
|
285
284
|
specification_version: 4
|
286
285
|
summary: Active Model style RDF ORM
|
@@ -303,7 +302,6 @@ test_files:
|
|
303
302
|
- spec/tripod/repository_spec.rb
|
304
303
|
- spec/tripod/resource_spec.rb
|
305
304
|
- spec/tripod/serialization_spec.rb
|
306
|
-
- spec/tripod/sparql_client_spec.rb
|
307
305
|
- spec/tripod/sparql_query_spec.rb
|
308
306
|
- spec/tripod/state_spec.rb
|
309
307
|
- spec/tripod/streaming_spec.rb
|
@@ -1,128 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Tripod::SparqlClient do
|
4
|
-
describe Data do
|
5
|
-
|
6
|
-
let(:data) { 'some-data-goes-here' }
|
7
|
-
|
8
|
-
describe "Query#query" do
|
9
|
-
|
10
|
-
let(:query) { "SELECT * WHERE {?s ?p ?o}" }
|
11
|
-
let(:bad_query) { "SELECT * WHERE ?s ?p ?o}" }
|
12
|
-
|
13
|
-
before do
|
14
|
-
p = Person.new('http://example.com/id/garry')
|
15
|
-
p.name = "garry"
|
16
|
-
p.save!
|
17
|
-
p
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "using Tripod::Streaming to get the data" do
|
21
|
-
before(:each) do
|
22
|
-
Tripod::Streaming.stub(get_data: "some data")
|
23
|
-
end
|
24
|
-
|
25
|
-
example do
|
26
|
-
Tripod::SparqlClient::Query.query(query, "application/sparql-results+json")
|
27
|
-
|
28
|
-
expect(Tripod::Streaming).to have_received(:get_data).with(
|
29
|
-
Tripod.query_endpoint,
|
30
|
-
"query=#{CGI.escape(query)}",
|
31
|
-
{
|
32
|
-
accept: "application/sparql-results+json",
|
33
|
-
timeout_seconds: Tripod.timeout_seconds,
|
34
|
-
response_limit_bytes: Tripod.response_limit_bytes
|
35
|
-
}
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with an integer response limit (number of bytes)" do
|
40
|
-
it "uses the limit" do
|
41
|
-
Tripod::SparqlClient::Query.query(
|
42
|
-
query, "application/sparql-results+json", {}, 1024
|
43
|
-
)
|
44
|
-
|
45
|
-
expect(Tripod::Streaming).to have_received(:get_data).with(
|
46
|
-
kind_of(String), kind_of(String), hash_including(response_limit_bytes: 1024)
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "with a :default response limit" do
|
52
|
-
it "uses the Tripod response limit" do
|
53
|
-
Tripod::SparqlClient::Query.query(
|
54
|
-
query, "application/sparql-results+json", {}, :default
|
55
|
-
)
|
56
|
-
|
57
|
-
expect(Tripod::Streaming).to have_received(:get_data).with(
|
58
|
-
kind_of(String), kind_of(String), hash_including(:response_limit_bytes)
|
59
|
-
)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "with a :no_response_limit response limit" do
|
64
|
-
it "doesn't pass a limit" do
|
65
|
-
Tripod::SparqlClient::Query.query(
|
66
|
-
query, "application/sparql-results+json", {}, :no_response_limit
|
67
|
-
)
|
68
|
-
|
69
|
-
expect(Tripod::Streaming).to have_received(:get_data).with(
|
70
|
-
kind_of(String), kind_of(String), hash_not_including(:response_limit_bytes)
|
71
|
-
)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should execute the query and return the format requested" do
|
77
|
-
JSON.parse(Tripod::SparqlClient::Query.query(query, "application/sparql-results+json"))["results"]["bindings"].length > 0
|
78
|
-
end
|
79
|
-
|
80
|
-
context "with a bad query" do
|
81
|
-
it "should raise a bad request error" do
|
82
|
-
lambda {
|
83
|
-
Tripod::SparqlClient::Query.query(bad_query, "application/sparql-results+json")
|
84
|
-
}.should raise_error
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "Data#append" do
|
90
|
-
it "should add the graph uri to the configured data endpoint" do
|
91
|
-
RestClient::Request.should_receive(:execute).with(hash_including(url: 'http://127.0.0.1:3030/tripod-test/data?graph=http://example.com/foo'))
|
92
|
-
Tripod::SparqlClient::Data.append('http://example.com/foo', data)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should send the data as the payload" do
|
96
|
-
RestClient::Request.should_receive(:execute).with(hash_including(payload: data))
|
97
|
-
Tripod::SparqlClient::Data.append('http://example.com/foo', data)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should HTTP POST the data" do
|
101
|
-
RestClient::Request.should_receive(:execute).with(hash_including(method: :post))
|
102
|
-
Tripod::SparqlClient::Data.append('http://example.com/foo', data)
|
103
|
-
end
|
104
|
-
|
105
|
-
context "which fails with a 400 error" do
|
106
|
-
before do
|
107
|
-
WebMock.enable!
|
108
|
-
stub_http_request(:post, 'http://127.0.0.1:3030/tripod-test/data?graph=http://example.com/foo').to_return(body: 'Error 400: Trousers missing', status: 400)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should raise a 'parse failed' exception" do
|
112
|
-
lambda { Tripod::SparqlClient::Data.append('http://example.com/foo', data) }.should raise_error(Tripod::Errors::BadDataRequest)
|
113
|
-
end
|
114
|
-
|
115
|
-
after do
|
116
|
-
WebMock.disable!
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "Data#replace" do
|
122
|
-
it "should HTTP PUT the data" do
|
123
|
-
RestClient::Request.should_receive(:execute).with(hash_including(method: :put))
|
124
|
-
Tripod::SparqlClient::Data.replace('http://example.com/foo', data)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|