tripod 0.7.9 → 0.7.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tripod/criteria/execution.rb +1 -4
- data/lib/tripod/finders.rb +5 -13
- data/lib/tripod/predicates.rb +2 -2
- data/lib/tripod/version.rb +1 -1
- data/spec/tripod/criteria_execution_spec.rb +2 -15
- data/spec/tripod/predicates_spec.rb +13 -0
- metadata +21 -21
@@ -10,13 +10,11 @@ module Tripod
|
|
10
10
|
# +ResourceCollection+ is an +Enumerable+, Array-like object.
|
11
11
|
#
|
12
12
|
# @option options [ String ] return_graph Indicates whether to return the graph as one of the variables.
|
13
|
-
# @option options [ Boolean ] only_set_fields Indicates whether to set only the declared fields on the resources. (default false).
|
14
13
|
def resources(opts={})
|
15
14
|
Tripod::ResourceCollection.new(
|
16
|
-
self.resource_class._resources_from_sparql(build_select_query(opts)
|
15
|
+
self.resource_class._resources_from_sparql(build_select_query(opts)),
|
17
16
|
# pass in the criteria that was used to generate this collection, as well as whether the user specified return graph
|
18
17
|
:return_graph => (opts.has_key?(:return_graph) ? opts[:return_graph] : true),
|
19
|
-
:only_set_fields => opts[:only_set_fields],
|
20
18
|
:criteria => self
|
21
19
|
)
|
22
20
|
end
|
@@ -33,7 +31,6 @@ module Tripod
|
|
33
31
|
# Execute the query and return the first result as a hydrated resource
|
34
32
|
#
|
35
33
|
# @option options [ String ] return_graph Indicates whether to return the graph as one of the variables.
|
36
|
-
# @option options [ Boolean ] only_set_fields Indicates whether to set only the declared fields on the resources. (default false).
|
37
34
|
def first(opts={})
|
38
35
|
sq = Tripod::SparqlQuery.new(build_select_query(opts))
|
39
36
|
first_sparql = sq.as_first_query_str
|
data/lib/tripod/finders.rb
CHANGED
@@ -59,7 +59,6 @@ module Tripod::Finders
|
|
59
59
|
#
|
60
60
|
# @option options [ String ] uri_variable The name of the uri variable in thh query, if not 'uri'
|
61
61
|
# @option options [ String ] graph_variable The name of the uri variable in thh query, if not 'graph'
|
62
|
-
# @option options [ Boolean ] only_set_fields Indicates whether to set only the declared fields on the resources. (default false).
|
63
62
|
#
|
64
63
|
# @return [ Array ] An array of hydrated resources of this class's type.
|
65
64
|
def find_by_sparql(sparql_query, opts={})
|
@@ -116,8 +115,7 @@ module Tripod::Finders
|
|
116
115
|
# given a sparql select query, create and hydrate some resources
|
117
116
|
#
|
118
117
|
# @option options [ String ] uri_variable The name of the uri variable in the query, if not 'uri'
|
119
|
-
# @option options [ String ] graph_variable The name of the uri variable in
|
120
|
-
# @option options [ Boolean ] only_set_fields Indicates whether to set only the declared fields on the resources. (default false).
|
118
|
+
# @option options [ String ] graph_variable The name of the uri variable in thh query, if not 'graph'
|
121
119
|
def _resources_from_sparql(select_sparql, opts={})
|
122
120
|
_create_and_hydrate_resources_from_sparql(select_sparql, opts)
|
123
121
|
end
|
@@ -145,13 +143,12 @@ module Tripod::Finders
|
|
145
143
|
#
|
146
144
|
# @option options [ String ] uri_variable The name of the uri variable in the query, if not 'uri'
|
147
145
|
# @option options [ String ] graph_variable The name of the uri variable in the query, if not 'graph'
|
148
|
-
# @option options [ Boolean ] only_set_fields Indicates whether to set only the declared fields on the resources. (default false).
|
149
146
|
def _create_and_hydrate_resources_from_sparql(select_sparql, opts={})
|
150
147
|
# TODO: Optimization?: if return_graph option is false, then don't do this next line?
|
151
148
|
uris_and_graphs = _select_uris_and_graphs(select_sparql, :uri_variable => opts[:uri_variable], :graph_variable => opts[:graph_variable])
|
152
149
|
ntriples_string = _raw_describe_select_results(select_sparql, :uri_variable => opts[:uri_variable]) # this defaults to ntriples
|
153
150
|
graph = _rdf_graph_from_ntriples_string(ntriples_string, graph=nil)
|
154
|
-
_resources_from_graph(graph, uris_and_graphs
|
151
|
+
_resources_from_graph(graph, uris_and_graphs)
|
155
152
|
end
|
156
153
|
|
157
154
|
# For a select query, generate a query which DESCRIBES all the results
|
@@ -172,12 +169,10 @@ module Tripod::Finders
|
|
172
169
|
Tripod::SparqlClient::Query.query(query, accept_header)
|
173
170
|
end
|
174
171
|
|
175
|
-
#
|
172
|
+
# given a graph of data, and a hash of uris=>graphs, create and hydrate some resources.
|
176
173
|
# Note: if any of the graphs are not set in the hash,
|
177
174
|
# those resources can still be constructed, but not persisted back to DB.
|
178
|
-
|
179
|
-
# @option options [ Boolean ] only_set_fields Indicates whether to set only the declared fields on the resources. (default false).
|
180
|
-
def _resources_from_graph(graph, uris_and_graphs, opts={})
|
175
|
+
def _resources_from_graph(graph, uris_and_graphs)
|
181
176
|
repo = add_data_to_repository(graph)
|
182
177
|
resources = []
|
183
178
|
|
@@ -192,11 +187,8 @@ module Tripod::Finders
|
|
192
187
|
|
193
188
|
# make a graph of data for this resource's uri
|
194
189
|
data_graph = RDF::Graph.new
|
195
|
-
|
196
190
|
repo.query( [RDF::URI.new(u), :predicate, :object] ) do |statement|
|
197
|
-
|
198
|
-
data_graph << statement
|
199
|
-
end
|
191
|
+
data_graph << statement
|
200
192
|
end
|
201
193
|
|
202
194
|
# use it to hydrate this resource
|
data/lib/tripod/predicates.rb
CHANGED
@@ -69,11 +69,11 @@ module Tripod::Predicates
|
|
69
69
|
def append_to_predicate(predicate_uri, object )
|
70
70
|
raise Tripod::Errors::UriNotSet.new() unless @uri
|
71
71
|
|
72
|
-
@repository << RDF::Statement.new(
|
72
|
+
@repository << RDF::Statement.new(self.uri, RDF::URI.new(predicate_uri.to_s), object)
|
73
73
|
end
|
74
74
|
|
75
75
|
def remove_predicate(predicate_uri)
|
76
|
-
@repository.query( [
|
76
|
+
@repository.query( [self.uri, RDF::URI.new(predicate_uri.to_s), :object] ) do |statement|
|
77
77
|
@repository.delete( statement )
|
78
78
|
end
|
79
79
|
end
|
data/lib/tripod/version.rb
CHANGED
@@ -12,7 +12,6 @@ describe Tripod::Criteria do
|
|
12
12
|
|
13
13
|
let!(:john) do
|
14
14
|
p = Person.new('http://example.com/id/john')
|
15
|
-
p.write_predicate('http://example.com/this-is-not-declared-as-a-field', 'blah')
|
16
15
|
p.name = "John"
|
17
16
|
p.save!
|
18
17
|
p
|
@@ -97,8 +96,8 @@ describe Tripod::Criteria do
|
|
97
96
|
|
98
97
|
context "with options passed" do
|
99
98
|
it "should pass the options to build_select_query" do
|
100
|
-
person_criteria.should_receive(:build_select_query).with(:return_graph => false
|
101
|
-
person_criteria.resources(:return_graph => false
|
99
|
+
person_criteria.should_receive(:build_select_query).with(:return_graph => false).and_call_original
|
100
|
+
person_criteria.resources(:return_graph => false)
|
102
101
|
end
|
103
102
|
end
|
104
103
|
|
@@ -132,18 +131,6 @@ describe Tripod::Criteria do
|
|
132
131
|
|
133
132
|
end
|
134
133
|
|
135
|
-
context "with the only_set_fields option set to true" do
|
136
|
-
it "should only populate predicates for fields that have been declared at class level" do
|
137
|
-
person_criteria.resources(:only_set_fields => true).first.read_predicate('http://example.com/this-is-not-declared-as-a-field').should be_empty
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "without setting the only_set_fields option (i.e. false)" do
|
142
|
-
it "should only populate all preciates that have been declared at class level" do
|
143
|
-
person_criteria.resources.first.read_predicate('http://example.com/this-is-not-declared-as-a-field').should_not be_empty
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
134
|
end
|
148
135
|
|
149
136
|
describe "#first" do
|
@@ -76,6 +76,19 @@ describe Tripod::Predicates do
|
|
76
76
|
person.remove_predicate('http://example.com/blog')
|
77
77
|
person.read_predicate('http://example.com/blog').should be_empty
|
78
78
|
end
|
79
|
+
|
80
|
+
context 'when there are other triples in the repository that share the same predicate' do
|
81
|
+
let(:subject) { RDF::URI.new('http://foo') }
|
82
|
+
let(:predicate) { RDF::URI.new('http://example.com/blog') }
|
83
|
+
before do
|
84
|
+
person.repository << [subject, predicate, RDF::URI.new('http://foo.tumblr.com')]
|
85
|
+
end
|
86
|
+
|
87
|
+
it "doesn't remove a value where the subject of the triple isn't the resource's URI" do
|
88
|
+
person.remove_predicate('http://example.com/blog')
|
89
|
+
person.repository.query( [subject, predicate, :object] ).should_not be_empty
|
90
|
+
end
|
91
|
+
end
|
79
92
|
end
|
80
93
|
|
81
94
|
describe "#append_to_predicate" 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.7.
|
4
|
+
version: 0.7.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -15,7 +15,7 @@ date: 2013-05-07 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rest-client
|
18
|
-
requirement: &
|
18
|
+
requirement: &70302396722560 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70302396722560
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
|
-
requirement: &
|
29
|
+
requirement: &70302396722020 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '3.2'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70302396722020
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: equivalent-xml
|
40
|
-
requirement: &
|
40
|
+
requirement: &70302396721600 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70302396721600
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: rdf
|
51
|
-
requirement: &
|
51
|
+
requirement: &70302396737420 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: '1.0'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *70302396737420
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: rdf-rdfxml
|
62
|
-
requirement: &
|
62
|
+
requirement: &70302396737000 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ! '>='
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: '0'
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *70302396737000
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rdf-n3
|
73
|
-
requirement: &
|
73
|
+
requirement: &70302396736540 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ! '>='
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '0'
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *70302396736540
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: rdf-json
|
84
|
-
requirement: &
|
84
|
+
requirement: &70302396736120 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|
@@ -89,10 +89,10 @@ dependencies:
|
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *70302396736120
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: json-ld
|
95
|
-
requirement: &
|
95
|
+
requirement: &70302396735700 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
98
98
|
- - ! '>='
|
@@ -100,10 +100,10 @@ dependencies:
|
|
100
100
|
version: '0'
|
101
101
|
type: :runtime
|
102
102
|
prerelease: false
|
103
|
-
version_requirements: *
|
103
|
+
version_requirements: *70302396735700
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: guid
|
106
|
-
requirement: &
|
106
|
+
requirement: &70302396735280 !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|
109
109
|
- - ! '>='
|
@@ -111,10 +111,10 @@ dependencies:
|
|
111
111
|
version: '0'
|
112
112
|
type: :runtime
|
113
113
|
prerelease: false
|
114
|
-
version_requirements: *
|
114
|
+
version_requirements: *70302396735280
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: dalli
|
117
|
-
requirement: &
|
117
|
+
requirement: &70302396734780 !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|
120
120
|
- - ~>
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
version: '2.6'
|
123
123
|
type: :runtime
|
124
124
|
prerelease: false
|
125
|
-
version_requirements: *
|
125
|
+
version_requirements: *70302396734780
|
126
126
|
description: RDF ruby ORM
|
127
127
|
email:
|
128
128
|
- ric@swirrl.com
|