rdf-mongo 1.99.0 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e3195ca4d5d5ad17d35bd15054f50cd7c9bff23
4
- data.tar.gz: c1974fdf7ed3ed53c454b34dbdb64332037eaaf0
3
+ metadata.gz: bf15f8c6d12d55bd85991a3e6bf8ab4ee318568b
4
+ data.tar.gz: 78e563de1eccb9af04635ebf61cd3b8feb181858
5
5
  SHA512:
6
- metadata.gz: 55b5d27957f3005d8baaf891ba5782da2be7f1a3d7ff313c8e9d76bdf57618ee8bce5d14bfd411317965deb2c0cf0aebbdff0d000135a8df405c3f494d30e82e
7
- data.tar.gz: 74fa5f4c341246983df4b01c1dee4698d0b6298ba52fa19f6370d20e688bf9a6fc133399529a24725c1b9db88f45af79f579ce4230cda3a4cc65128b2aa4c4b4
6
+ metadata.gz: bf281484d6946e53cd6edaf7c83715fe98021f4114cfaf2efad1c1525eb6b39f2ae90de862cdbaa38e6df54513855bd6dfe547356e433ae38657c16e67d34ccf
7
+ data.tar.gz: 87489d3773aaed971a6060d37139a22440d493ca1ad321fa2e141e1f0e35672212dde03a8a37ea350edd60d8af1b1398b71f85bdab7b640e33c154b181ecf075
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.99.0
1
+ 2.0.0.beta1
@@ -15,6 +15,6 @@ module RDF::Mongo
15
15
 
16
16
  ##
17
17
  # @return [Array(Integer, Integer, Integer)]
18
- def self.to_a() [MAJOR, MINOR, TINY] end
18
+ def self.to_a() STRING.split(".") end
19
19
  end
20
20
  end
data/lib/rdf/mongo.rb CHANGED
@@ -80,7 +80,7 @@ module RDF
80
80
  t, k1, lt = :ct, :c, :cl
81
81
  end
82
82
  h = {k1 => v, t => k, lt => ll}
83
- h.delete_if {|k,v| h[k].nil?}
83
+ h.delete_if {|kk,_| h[kk].nil?}
84
84
  end
85
85
 
86
86
  ##
@@ -108,41 +108,63 @@ module RDF
108
108
 
109
109
  class Repository < ::RDF::Repository
110
110
  # The Mongo database instance
111
- # @!attribute [r] db
112
111
  # @return [Mongo::DB]
113
- attr_reader :db
112
+ attr_reader :client
114
113
 
115
114
  # The collection used for storing quads
116
- # @!attribute [r] coll
117
115
  # @return [Mongo::Collection]
118
- attr_reader :coll
116
+ attr_reader :collection
119
117
 
120
118
  ##
121
119
  # Initializes this repository instance.
122
120
  #
123
- # @param [Hash{Symbol => Object}] options
124
- # @option options [URI, #to_s] :uri (nil)
125
- # @option options [String, #to_s] :title (nil)
126
- # @option options [String] :host
127
- # @option options [Integer] :port
128
- # @option options [String] :db
129
- # @option options [String] :user for authentication
130
- # @option options [String] :password for authentication
131
- # @option options [String] :collection ('quads')
121
+ # @overload initialize(options = {}, &block)
122
+ # @param [Hash{Symbol => Object}] options
123
+ # @option options [String, #to_s] :title (nil)
124
+ # @option options [URI, #to_s] :uri (nil)
125
+ # URI in the form `mongodb://host:port/db`. The URI should also identify the collection use, but appending a `collection` path component such as `mongodb://host:port/db/collection`, this ensures that the collection will be maintained if cloned. See [Mongo::Client options](https://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial-2-0/#uri-options-conversions) for more information on Mongo URIs.
126
+ #
127
+ # @overload initialize(options = {}, &block)
128
+ # @param [Hash{Symbol => Object}] options
129
+ # See [Mongo::Client options](https://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial-2-0/#uri-options-conversions) for more information on Mongo Client options.
130
+ # @option options [String, #to_s] :title (nil)
131
+ # @option options [String] :host
132
+ # a single address or an array of addresses, which may contain a port designation
133
+ # @option options [Integer] :port (27017) applied to host address(es)
134
+ # @option options [String] :database ('quadb')
135
+ # @option options [String] :collection ('quads')
136
+ #
132
137
  # @yield [repository]
133
138
  # @yieldparam [Repository] repository
134
139
  def initialize(options = {}, &block)
135
- options = {host: 'localhost', port: 27017, db: 'quadb', collection: 'quads'}.merge(options)
136
- @db = ::Mongo::Connection.new(options[:host], options[:port]).db(options[:db])
137
- @db.authenticate(options[:user], options[:password]) if options[:user] && options[:password]
138
- @coll = @db[options[:collection]]
139
- @coll.create_index("s")
140
- @coll.create_index("p")
141
- @coll.create_index("o")
142
- @coll.create_index("c")
143
- @coll.create_index([["s", ::Mongo::ASCENDING], ["p", ::Mongo::ASCENDING]])
144
- @coll.create_index([["s", ::Mongo::ASCENDING], ["o", ::Mongo::ASCENDING]])
145
- @coll.create_index([["p", ::Mongo::ASCENDING], ["o", ::Mongo::ASCENDING]])
140
+ collection = nil
141
+ if options[:uri]
142
+ options = options.dup
143
+ uri = RDF::URI(options.delete(:uri))
144
+ _, db, coll = uri.path.split('/')
145
+ collection = coll || options.delete(:collection)
146
+ db ||= "quadb"
147
+ uri.path = "/#{db}" if coll
148
+ @client = ::Mongo::Client.new(uri.to_s, options)
149
+ else
150
+ warn "[DEPRECATION] RDF::Mongo::Repository#initialize expects a uri argument. Called from #{Gem.location_of_caller.join(':')}" unless options.empty?
151
+ options[:database] ||= options.delete(:db) # 1.x compat
152
+ options[:database] ||= 'quadb'
153
+ hosts = Array(options[:host] || 'localhost')
154
+ hosts.map! {|h| "#{h}:#{options[:port]}"} if options[:port]
155
+ @client = ::Mongo::Client.new(hosts, options)
156
+ end
157
+
158
+ @collection = @client[options.delete(:collection) || 'quads']
159
+ @collection.indexes.create_many([
160
+ {key: {s: 1}},
161
+ {key: {p: 1}},
162
+ {key: {o: "hashed"}},
163
+ {key: {c: 1}},
164
+ {key: {s: 1, p: 1}},
165
+ #{key: {s: 1, o: "hashed"}}, # Muti-key hashed indexes not allowed
166
+ #{key: {p: 1, o: "hashed"}}, # Muti-key hashed indexes not allowed
167
+ ])
146
168
  super(options, &block)
147
169
  end
148
170
 
@@ -150,6 +172,7 @@ module RDF
150
172
  def supports?(feature)
151
173
  case feature.to_sym
152
174
  when :graph_name then true
175
+ when :validity then @options.fetch(:with_validity, true)
153
176
  else false
154
177
  end
155
178
  end
@@ -159,16 +182,16 @@ module RDF
159
182
  st_mongo = statement.to_mongo
160
183
  st_mongo[:ct] ||= :default # Indicate statement is in the default graph
161
184
  #puts "insert statement: #{st_mongo.inspect}"
162
- @coll.update(st_mongo, st_mongo, upsert: true)
185
+ @collection.update_one(st_mongo, st_mongo, upsert: true)
163
186
  end
164
187
 
165
188
  # @see RDF::Mutable#delete_statement
166
189
  def delete_statement(statement)
167
190
  case statement.graph_name
168
191
  when nil
169
- @coll.remove(statement.to_mongo.merge('ct'=>:default))
192
+ @collection.delete_one(statement.to_mongo.merge('ct'=>:default))
170
193
  else
171
- @coll.remove(statement.to_mongo)
194
+ @collection.delete_one(statement.to_mongo)
172
195
  end
173
196
  end
174
197
 
@@ -180,24 +203,24 @@ module RDF
180
203
  ##
181
204
  # @private
182
205
  # @see RDF::Countable#empty?
183
- def empty?; @coll.count == 0; end
206
+ def empty?; @collection.count == 0; end
184
207
 
185
208
  ##
186
209
  # @private
187
210
  # @see RDF::Countable#count
188
211
  def count
189
- @coll.count
212
+ @collection.count
190
213
  end
191
214
 
192
215
  def clear_statements
193
- @coll.remove
216
+ @collection.delete_many
194
217
  end
195
218
 
196
219
  ##
197
220
  # @private
198
221
  # @see RDF::Enumerable#has_statement?
199
222
  def has_statement?(statement)
200
- !!@coll.find_one(statement.to_mongo)
223
+ @collection.find(statement.to_mongo).count > 0
201
224
  end
202
225
  ##
203
226
  # @private
@@ -205,10 +228,8 @@ module RDF
205
228
  def each_statement(&block)
206
229
  @nodes = {} # reset cache. FIXME this should probably be in Node.intern
207
230
  if block_given?
208
- @coll.find() do |cursor|
209
- cursor.each do |data|
210
- block.call(RDF::Statement.from_mongo(data))
211
- end
231
+ @collection.find().each do |document|
232
+ block.call(RDF::Statement.from_mongo(document))
212
233
  end
213
234
  end
214
235
  enum_statement
@@ -219,7 +240,7 @@ module RDF
219
240
  # @private
220
241
  # @see RDF::Enumerable#has_graph?
221
242
  def has_graph?(value)
222
- !!@coll.find_one(RDF::Mongo::Conversion.to_mongo(value, :context))
243
+ @collection.find(RDF::Mongo::Conversion.to_mongo(value, :graph_name)).count > 0
223
244
  end
224
245
 
225
246
  protected
@@ -228,17 +249,16 @@ module RDF
228
249
  # @private
229
250
  # @see RDF::Queryable#query_pattern
230
251
  # @see RDF::Query::Pattern
231
- def query_pattern(pattern, &block)
252
+ def query_pattern(pattern, options = {}, &block)
253
+ return enum_for(:query_pattern, pattern, options) unless block_given?
232
254
  @nodes = {} # reset cache. FIXME this should probably be in Node.intern
233
255
 
234
256
  # A pattern graph_name of `false` is used to indicate the default graph
235
257
  pm = pattern.to_mongo
236
258
  pm.merge!(c: nil, ct: :default) if pattern.graph_name == false
237
259
  #puts "query using #{pm.inspect}"
238
- @coll.find(pm) do |cursor|
239
- cursor.each do |data|
240
- block.call(RDF::Statement.from_mongo(data))
241
- end
260
+ @collection.find(pm).each do |document|
261
+ block.call(RDF::Statement.from_mongo(document))
242
262
  end
243
263
  end
244
264
 
metadata CHANGED
@@ -1,85 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.99.0
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pius Uzamere
8
+ - Gregg Kellogg
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
12
+ date: 2016-02-22 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rdf
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - "~>"
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 2.0.0.beta
21
+ - - "<"
18
22
  - !ruby/object:Gem::Version
19
- version: '1.99'
23
+ version: '3'
20
24
  type: :runtime
21
25
  prerelease: false
22
26
  version_requirements: !ruby/object:Gem::Requirement
23
27
  requirements:
24
- - - "~>"
28
+ - - ">="
25
29
  - !ruby/object:Gem::Version
26
- version: '1.99'
30
+ version: 2.0.0.beta
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
27
34
  - !ruby/object:Gem::Dependency
28
35
  name: mongo
29
36
  requirement: !ruby/object:Gem::Requirement
30
37
  requirements:
31
38
  - - "~>"
32
39
  - !ruby/object:Gem::Version
33
- version: '1.10'
40
+ version: '2.2'
34
41
  type: :runtime
35
42
  prerelease: false
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
45
  - - "~>"
39
46
  - !ruby/object:Gem::Version
40
- version: '1.10'
47
+ version: '2.2'
41
48
  - !ruby/object:Gem::Dependency
42
49
  name: rdf-spec
43
50
  requirement: !ruby/object:Gem::Requirement
44
51
  requirements:
45
- - - "~>"
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0.beta
55
+ - - "<"
46
56
  - !ruby/object:Gem::Version
47
- version: '1.99'
57
+ version: '3'
48
58
  type: :development
49
59
  prerelease: false
50
60
  version_requirements: !ruby/object:Gem::Requirement
51
61
  requirements:
52
- - - "~>"
62
+ - - ">="
53
63
  - !ruby/object:Gem::Version
54
- version: '1.99'
64
+ version: 2.0.0.beta
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: '3'
55
68
  - !ruby/object:Gem::Dependency
56
69
  name: rspec
57
70
  requirement: !ruby/object:Gem::Requirement
58
71
  requirements:
59
72
  - - "~>"
60
73
  - !ruby/object:Gem::Version
61
- version: '3.0'
74
+ version: '3.4'
62
75
  type: :development
63
76
  prerelease: false
64
77
  version_requirements: !ruby/object:Gem::Requirement
65
78
  requirements:
66
79
  - - "~>"
67
80
  - !ruby/object:Gem::Version
68
- version: '3.0'
81
+ version: '3.4'
69
82
  - !ruby/object:Gem::Dependency
70
83
  name: rspec-its
71
84
  requirement: !ruby/object:Gem::Requirement
72
85
  requirements:
73
86
  - - "~>"
74
87
  - !ruby/object:Gem::Version
75
- version: '1.0'
88
+ version: '1.2'
76
89
  type: :development
77
90
  prerelease: false
78
91
  version_requirements: !ruby/object:Gem::Requirement
79
92
  requirements:
80
93
  - - "~>"
81
94
  - !ruby/object:Gem::Version
82
- version: '1.0'
95
+ version: '1.2'
83
96
  - !ruby/object:Gem::Dependency
84
97
  name: yard
85
98
  requirement: !ruby/object:Gem::Requirement
@@ -98,19 +111,21 @@ dependencies:
98
111
  name: bson_ext
99
112
  requirement: !ruby/object:Gem::Requirement
100
113
  requirements:
101
- - - ">="
114
+ - - "~>"
102
115
  - !ruby/object:Gem::Version
103
- version: '0'
116
+ version: '1.12'
104
117
  type: :development
105
118
  prerelease: false
106
119
  version_requirements: !ruby/object:Gem::Requirement
107
120
  requirements:
108
- - - ">="
121
+ - - "~>"
109
122
  - !ruby/object:Gem::Version
110
- version: '0'
123
+ version: '1.12'
111
124
  description: rdf-mongo is a storage adapter for integrating MongoDB and rdf.rb, a
112
125
  Ruby library for working with Resource Description Framework (RDF) data.
113
- email: pius@alum.mit.edu
126
+ email:
127
+ - pius@alum.mit.edu
128
+ - gregg@greggkellogg.net
114
129
  executables: []
115
130
  extensions: []
116
131
  extra_rdoc_files: []
@@ -122,7 +137,7 @@ files:
122
137
  - lib/rdf/mongo/version.rb
123
138
  homepage: http://ruby-rdf.github.com/rdf-mongo
124
139
  licenses:
125
- - MIT License
140
+ - MIT
126
141
  metadata: {}
127
142
  post_install_message: Have fun! :)
128
143
  rdoc_options: []
@@ -132,15 +147,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
147
  requirements:
133
148
  - - ">="
134
149
  - !ruby/object:Gem::Version
135
- version: 1.9.3
150
+ version: '2.0'
136
151
  required_rubygems_version: !ruby/object:Gem::Requirement
137
152
  requirements:
138
- - - ">="
153
+ - - ">"
139
154
  - !ruby/object:Gem::Version
140
- version: '0'
155
+ version: 1.3.1
141
156
  requirements: []
142
157
  rubyforge_project:
143
- rubygems_version: 2.4.5.1
158
+ rubygems_version: 2.5.1
144
159
  signing_key:
145
160
  specification_version: 4
146
161
  summary: A storage adapter for integrating MongoDB and rdf.rb, a Ruby library for