tripod 0.7.9 → 0.7.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -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), :only_set_fields => opts[:only_set_fields]),
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
@@ -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 the query, if not 'graph'
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, :only_set_fields => opts[:only_set_fields])
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
- Given a graph of data, and a hash of uris=>graphs, create and hydrate some resources.
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
- if !opts[:only_set_fields] || self.fields.values.map{ |v| v.predicate.to_s }.include?(statement.predicate.to_s)
198
- data_graph << statement
199
- end
191
+ data_graph << statement
200
192
  end
201
193
 
202
194
  # use it to hydrate this resource
@@ -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(@uri, RDF::URI.new(predicate_uri.to_s), object)
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( [:subject, RDF::URI.new(predicate_uri.to_s), :object] ) do |statement|
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
@@ -1,3 +1,3 @@
1
1
  module Tripod
2
- VERSION = "0.7.9"
2
+ VERSION = "0.7.11"
3
3
  end
@@ -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, :only_set_fields => true).and_call_original
101
- person_criteria.resources(:return_graph => false, :only_set_fields => true)
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.9
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: &70100686885260 !ruby/object:Gem::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: *70100686885260
26
+ version_requirements: *70302396722560
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
- requirement: &70100686884720 !ruby/object:Gem::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: *70100686884720
37
+ version_requirements: *70302396722020
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: equivalent-xml
40
- requirement: &70100686884300 !ruby/object:Gem::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: *70100686884300
48
+ version_requirements: *70302396721600
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rdf
51
- requirement: &70100686883760 !ruby/object:Gem::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: *70100686883760
59
+ version_requirements: *70302396737420
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rdf-rdfxml
62
- requirement: &70100686883340 !ruby/object:Gem::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: *70100686883340
70
+ version_requirements: *70302396737000
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rdf-n3
73
- requirement: &70100686882880 !ruby/object:Gem::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: *70100686882880
81
+ version_requirements: *70302396736540
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: rdf-json
84
- requirement: &70100686882460 !ruby/object:Gem::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: *70100686882460
92
+ version_requirements: *70302396736120
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: json-ld
95
- requirement: &70100686882040 !ruby/object:Gem::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: *70100686882040
103
+ version_requirements: *70302396735700
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: guid
106
- requirement: &70100686881620 !ruby/object:Gem::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: *70100686881620
114
+ version_requirements: *70302396735280
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: dalli
117
- requirement: &70100686881120 !ruby/object:Gem::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: *70100686881120
125
+ version_requirements: *70302396734780
126
126
  description: RDF ruby ORM
127
127
  email:
128
128
  - ric@swirrl.com