rdf-mongo 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/rdf/mongo.rb +41 -19
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ba46fdb7cc95f3017ddac7c8d0c9e5d0edfb173
4
- data.tar.gz: 4050a42ef2a009515c4de49e4dff7d064a3a7a6e
3
+ metadata.gz: 2a91d8405fa246651fce9d3c97b3da32b26c1380
4
+ data.tar.gz: 93c268a404411577b276771ddb8f7c8b82cc91ec
5
5
  SHA512:
6
- metadata.gz: b340c6b9236bcafb82203b7db8927ad25d020b91c176de378740b844cb9a1831db37985b7e39bcb05fc03e820cf81de045863a41981d8139889c2e0fa330ffb5
7
- data.tar.gz: 6cd96cbcb02395a4396e0091cf0b3e8935a0240af6d46b2c536637a96868ab461f0df1b487b6922bd0851f34d8a320b4069c4faba438e9866b50a212b29c422c
6
+ metadata.gz: 28afd467cc19bccfc1bbe4e4cdb830ad0e764f57f7742047be32f4b8f3b83d3030f42a1bbdcbb88f8db68861a10f50b0cb8d78ddcb49c11d3f212fd6402b2732
7
+ data.tar.gz: e903f0f0b89bde195e847643a84fcc0f64d44519510d7de49d46545271ef65fbb5a5b6cd203eea36f081d07b019fa9e5faa853f529247f349b157bdcf88ea942
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.1
@@ -8,11 +8,11 @@ module RDF
8
8
  # Creates a BSON representation of the statement.
9
9
  # @return [Hash]
10
10
  def to_mongo
11
- self.to_hash.inject({}) do |hash, (place_in_statement, entity)|
12
- hash.merge(RDF::Mongo::Conversion.to_mongo(entity, place_in_statement))
11
+ self.to_hash.inject({}) do |hash, (place_in_statement, entity)|
12
+ hash.merge(RDF::Mongo::Conversion.to_mongo(entity, place_in_statement))
13
13
  end
14
14
  end
15
-
15
+
16
16
  ##
17
17
  # Create BSON for a statement representation. Note that if the statement has no graph name,
18
18
  # a value of `false` will be used to indicate the default context
@@ -27,7 +27,7 @@ module RDF
27
27
  graph_name: RDF::Mongo::Conversion.from_mongo(statement['c'], statement['ct'], statement['cl']))
28
28
  end
29
29
  end
30
-
30
+
31
31
  module Mongo
32
32
  autoload :VERSION, "rdf/mongo/version"
33
33
 
@@ -68,7 +68,7 @@ module RDF
68
68
  v, k = value.to_s, :u
69
69
  end
70
70
  v = nil if v == ''
71
-
71
+
72
72
  case place_in_statement
73
73
  when :subject
74
74
  t, k1, lt = :st, :s, :sl
@@ -114,7 +114,7 @@ module RDF
114
114
  # The collection used for storing quads
115
115
  # @return [Mongo::Collection]
116
116
  attr_reader :collection
117
-
117
+
118
118
  ##
119
119
  # Initializes this repository instance.
120
120
  #
@@ -171,28 +171,36 @@ module RDF
171
171
  # @see RDF::Mutable#insert_statement
172
172
  def supports?(feature)
173
173
  case feature.to_sym
174
- when :graph_name then true
174
+ when :graph_name then true
175
+ when :atomic_write then true
175
176
  when :validity then @options.fetch(:with_validity, true)
176
177
  else false
177
178
  end
178
179
  end
179
-
180
+
181
+ def apply_changeset(changeset)
182
+ ops = []
183
+
184
+ changeset.deletes.each do |d|
185
+ ops << { delete_one: { filter: statement_to_delete(d)} }
186
+ end
187
+
188
+ changeset.inserts.each do |i|
189
+ ops << { update_one: { filter: statement_to_insert(i), update: statement_to_insert(i), upsert: true} }
190
+ end
191
+
192
+ @collection.bulk_write(ops, ordered: true)
193
+ end
194
+
180
195
  def insert_statement(statement)
181
- raise ArgumentError, "Statement #{statement.inspect} is incomplete" if statement.incomplete?
182
- st_mongo = statement.to_mongo
183
- st_mongo[:ct] ||= :default # Indicate statement is in the default graph
184
- #puts "insert statement: #{st_mongo.inspect}"
196
+ st_mongo = statement_to_insert(statement)
185
197
  @collection.update_one(st_mongo, st_mongo, upsert: true)
186
198
  end
187
199
 
188
200
  # @see RDF::Mutable#delete_statement
189
201
  def delete_statement(statement)
190
- case statement.graph_name
191
- when nil
192
- @collection.delete_one(statement.to_mongo.merge('ct'=>:default))
193
- else
194
- @collection.delete_one(statement.to_mongo)
195
- end
202
+ st_mongo = statement_to_delete(statement)
203
+ @collection.delete_one(st_mongo)
196
204
  end
197
205
 
198
206
  ##
@@ -261,13 +269,27 @@ module RDF
261
269
  block.call(RDF::Statement.from_mongo(document))
262
270
  end
263
271
  end
264
-
272
+
265
273
  private
266
274
 
267
275
  def enumerator! # @private
268
276
  require 'enumerator' unless defined?(::Enumerable)
269
277
  @@enumerator_klass = defined?(::Enumerable::Enumerator) ? ::Enumerable::Enumerator : ::Enumerator
270
278
  end
279
+
280
+ def statement_to_insert(statement)
281
+ raise ArgumentError, "Statement #{statement.inspect} is incomplete" if statement.incomplete?
282
+ st_mongo = statement.to_mongo
283
+ st_mongo[:ct] ||= :default # Indicate statement is in the default graph
284
+ #puts "insert statement: #{st_mongo.inspect}"
285
+ st_mongo
286
+ end
287
+
288
+ def statement_to_delete(statement)
289
+ st_mongo = statement.to_mongo
290
+ st_mongo[:ct] = :default if statement.graph_name.nil?
291
+ st_mongo
292
+ end
271
293
  end
272
294
  end
273
295
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pius Uzamere
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-10 00:00:00.000000000 Z
12
+ date: 2016-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.4.8
132
+ rubygems_version: 2.5.1
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: A storage adapter for integrating MongoDB and rdf.rb, a Ruby library for