mongo_mapper 0.15.4 → 0.15.5
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/README.md +4 -0
- data/lib/mongo_mapper/document.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/proxy/proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/keys.rb +14 -2
- data/lib/mongo_mapper/plugins/querying.rb +2 -2
- data/lib/mongo_mapper/plugins/shardable.rb +30 -0
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/mongo_mapper.rb +1 -0
- data/spec/examples.txt +1698 -1691
- data/spec/functional/shardable_spec.rb +67 -0
- data/spec/unit/associations/proxy_spec.rb +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae0bcdb6320444b591dc779d739c553ba371c86e8465c4547c5e35423fe37ade
|
4
|
+
data.tar.gz: 270341e4efc65ba09578c2ba889c3c2e560610cf6eddfa7889fee19ded37c760
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz: '
|
6
|
+
metadata.gz: 3af02a093ffb4f9b13f48557bd83689c5cdcf35e434c00b152be18ad33e520e9ffbf1b7817b90ac4d363fe6f4452bab2ee66c5c450aca65981cc29ac2e74fe89
|
7
|
+
data.tar.gz: '09f802a3351959d626e23b4a6fa331ef10749a3b2f259440b527b26a25a23d0f0684c1e2bf0001938357e76fe5664da481ff298b572e665ded6afe0feb5fb286'
|
data/README.md
CHANGED
@@ -52,6 +52,10 @@ Note, if you are using Ruby 3.0+, you'll need Rails 6.
|
|
52
52
|
* Commit, do not mess with Rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself in another branch so a maintainer can ignore it when your pull request is merged.
|
53
53
|
* Send a pull request. Bonus points for topic branches.
|
54
54
|
|
55
|
+
## How to release
|
56
|
+
|
57
|
+
See `HOW_TO_RELEASE.md`
|
58
|
+
|
55
59
|
## Problems or Questions?
|
56
60
|
|
57
61
|
Hit up the Google group: http://groups.google.com/group/mongomapper
|
@@ -38,6 +38,7 @@ module MongoMapper
|
|
38
38
|
:nil?,
|
39
39
|
:blank?,
|
40
40
|
:present?,
|
41
|
+
:hash,
|
41
42
|
# Active support in rails 3 beta 4 can override to_json after this is loaded,
|
42
43
|
# at least when run in mongomapper tests. The implementation was changed in master
|
43
44
|
# some time after this, so not sure whether this is still a problem.
|
@@ -251,12 +251,24 @@ module MongoMapper
|
|
251
251
|
|
252
252
|
def remove_validate_callbacks(a_name)
|
253
253
|
chain = _validate_callbacks.dup.reject do |callback|
|
254
|
-
f = callback
|
254
|
+
f = callback_filter(callback)
|
255
255
|
f.respond_to?(:attributes) && f.attributes == a_name
|
256
256
|
end
|
257
257
|
reset_callbacks(:validate)
|
258
258
|
chain.each do |callback|
|
259
|
-
set_callback 'validate', callback
|
259
|
+
set_callback 'validate', callback_filter(callback)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
# The interface to obtain @filter from ActiveSupport::Callbacks::Callback has changed since rails 7.0.
|
264
|
+
# https://github.com/rails/rails/commit/d5ac941ddc3de7ad1aaff80ed67aa04fb626a263#diff-bf79b7ea0085308139af6de0afad9a9f22f13d4563cc56d784994414d88c5dd1
|
265
|
+
if ActiveSupport::VERSION::MAJOR >= 7
|
266
|
+
def callback_filter(callback)
|
267
|
+
callback.filter
|
268
|
+
end
|
269
|
+
else
|
270
|
+
def callback_filter(callback)
|
271
|
+
callback.raw_filter
|
260
272
|
end
|
261
273
|
end
|
262
274
|
end
|
@@ -148,7 +148,7 @@ module MongoMapper
|
|
148
148
|
when :insert
|
149
149
|
collection.insert_one(update, query_options)
|
150
150
|
when :save
|
151
|
-
collection.update_one({:_id => _id}, update, query_options.merge(upsert: true))
|
151
|
+
collection.update_one({:_id => _id}.merge(shard_key_filter), update, query_options.merge(upsert: true))
|
152
152
|
when :update
|
153
153
|
update.stringify_keys!
|
154
154
|
|
@@ -180,4 +180,4 @@ module MongoMapper
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
end
|
183
|
-
end
|
183
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Plugins
|
3
|
+
module Shardable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :shard_key_fields
|
8
|
+
self.shard_key_fields = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def shard_key_filter
|
12
|
+
filter = {}
|
13
|
+
shard_key_fields.each do |field|
|
14
|
+
filter[field] = if new_record?
|
15
|
+
send(field)
|
16
|
+
else
|
17
|
+
changed_attributes.key?(field) ? changed_attributes[field] : send(field)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
filter
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
def shard_key(*fields)
|
25
|
+
self.shard_key_fields = fields.map(&:to_s).freeze
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/mongo_mapper/version.rb
CHANGED
data/lib/mongo_mapper.rb
CHANGED
@@ -60,6 +60,7 @@ module MongoMapper
|
|
60
60
|
autoload :Safe, 'mongo_mapper/plugins/safe'
|
61
61
|
autoload :Sci, 'mongo_mapper/plugins/sci'
|
62
62
|
autoload :Scopes, 'mongo_mapper/plugins/scopes'
|
63
|
+
autoload :Shardable, 'mongo_mapper/plugins/shardable'
|
63
64
|
autoload :Serialization, 'mongo_mapper/plugins/serialization'
|
64
65
|
autoload :Stats, 'mongo_mapper/plugins/stats'
|
65
66
|
autoload :StrongParameters, 'mongo_mapper/plugins/strong_parameters'
|