ndb-rails 1.23.1 → 1.23.3
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/ndb/rails/relation.rb +23 -6
- data/lib/ndb/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ad5aca739eddaf19c833931a7672bd30d0ed6476d0637ce9cd73f4e722bd20f
|
|
4
|
+
data.tar.gz: 01cdfb078dc4189b475fe9931fffb4821fb7ca7cdcc7f98a82d3c6cef6fa672d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2dc449bf0022b4b14a307e7e525f6642af966dc46cdf9d0d55d97b0986545ddb75befb92417140e9580d6ed5e4dd530d5ac6868d33627c6ae74d99547d60dad5
|
|
7
|
+
data.tar.gz: 58a8fc3bde98cde180ea34b7f26b96d0136291df36d1112b8a6e395c88d7f0aaa40a7dc9b416bae2dd8b74b02fcef0b485afe3d8f9865796eaf158643b851d07
|
data/lib/ndb/rails/relation.rb
CHANGED
|
@@ -139,14 +139,19 @@ module Ndb
|
|
|
139
139
|
|
|
140
140
|
# Atomic writes. The daemon matches the where and writes in one step on
|
|
141
141
|
# every match, so the where needs the id or an indexed field
|
|
142
|
-
# (Ndb::UnindexedMany otherwise).
|
|
143
|
-
#
|
|
144
|
-
#
|
|
142
|
+
# (Ndb::UnindexedMany otherwise). Returns the number of modified
|
|
143
|
+
# documents. It takes attributes, as Active Record (update(status: "x")
|
|
144
|
+
# is a $set, cast by the attribute types), the operators of
|
|
145
|
+
# Ndb::Client#update ("$inc" => { "n" => 1 }), or both: the attributes
|
|
146
|
+
# join the $set. Unlike Active Record, it runs no validation and no
|
|
147
|
+
# callback (as update_all).
|
|
145
148
|
def update(ops = nil, expire_in: nil, **ops_kw)
|
|
146
|
-
ops = (ops || {}).merge(ops_kw)
|
|
147
|
-
|
|
149
|
+
ops = (ops || {}).merge(ops_kw).transform_keys(&:to_s)
|
|
150
|
+
attrs, ops = ops.partition { |key, _| !key.start_with?("$") }.map(&:to_h)
|
|
148
151
|
|
|
149
|
-
raise ArgumentError, "update takes
|
|
152
|
+
raise ArgumentError, "update takes attributes (status: \"x\") or operators (\"$inc\" => { n: 1 })" if attrs.empty? && ops.empty?
|
|
153
|
+
|
|
154
|
+
ops = with_attributes(ops, attrs) unless attrs.empty?
|
|
150
155
|
|
|
151
156
|
klass.ndb_update(Conditions.combine(values[:where]), with_updated_at(ops), many: true, expire_in: expire_in).fetch("modified")
|
|
152
157
|
end
|
|
@@ -384,6 +389,18 @@ module Ndb
|
|
|
384
389
|
values[:keep_encrypted] ? Rails.client.keep_encrypted(&) : yield
|
|
385
390
|
end
|
|
386
391
|
|
|
392
|
+
# ops with attrs, cast by their types, in its $set. A field in both is
|
|
393
|
+
# refused: it is not clear which value wins.
|
|
394
|
+
def with_attributes(ops, attrs)
|
|
395
|
+
set = (ops["$set"] || {}).transform_keys(&:to_s)
|
|
396
|
+
doc = klass.send(:upsert_document, attrs)
|
|
397
|
+
both = set.keys & doc.keys
|
|
398
|
+
|
|
399
|
+
raise ArgumentError, "update sets #{both.join(", ")} twice: as an attribute and in $set" if both.any?
|
|
400
|
+
|
|
401
|
+
ops.merge("$set" => set.merge(doc))
|
|
402
|
+
end
|
|
403
|
+
|
|
387
404
|
# The operators with $set of updated_at, unless they write it already.
|
|
388
405
|
def with_updated_at(ops)
|
|
389
406
|
ops = ops.transform_keys(&:to_s)
|
data/lib/ndb/rails/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ndb-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.23.
|
|
4
|
+
version: 1.23.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thadeu
|
|
@@ -43,7 +43,7 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 1.23.
|
|
46
|
+
version: 1.23.3
|
|
47
47
|
- - "<"
|
|
48
48
|
- !ruby/object:Gem::Version
|
|
49
49
|
version: '2'
|
|
@@ -53,7 +53,7 @@ dependencies:
|
|
|
53
53
|
requirements:
|
|
54
54
|
- - ">="
|
|
55
55
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: 1.23.
|
|
56
|
+
version: 1.23.3
|
|
57
57
|
- - "<"
|
|
58
58
|
- !ruby/object:Gem::Version
|
|
59
59
|
version: '2'
|