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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 290286ec91fda33bce766c8cacff110abd4027b200fa5279c2ca8afdf68d3ad3
4
- data.tar.gz: b38548fb44300f730c70e0e43abe48a7a9785f884d8b28d3d7447afc78a77ec5
3
+ metadata.gz: ae0bcdb6320444b591dc779d739c553ba371c86e8465c4547c5e35423fe37ade
4
+ data.tar.gz: 270341e4efc65ba09578c2ba889c3c2e560610cf6eddfa7889fee19ded37c760
5
5
  SHA512:
6
- metadata.gz: eef0f965e3d2b23cafcbfe6d3c39581ef4556e2b606a1668e3c26a2817bd4a75a94635c5102795171f4deeef6a0b52c74ff3bcac6f81c83a69e69d746f369a0b
7
- data.tar.gz: '058f0007e68c8e8d3bbe5ea9236615ba252a44b12c5e91042390a8f920a4127cbe2950e8748f088daab02e8a7b8c6eb0a10b226c378cf4330951b1f8e94db898'
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
@@ -39,6 +39,7 @@ module MongoMapper
39
39
  include Plugins::PartialUpdates
40
40
  include Plugins::IdentityMap
41
41
  include Plugins::CounterCache
42
+ include Plugins::Shardable
42
43
 
43
44
  included do
44
45
  extend Plugins
@@ -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.raw_filter
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.raw_filter
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
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module MongoMapper
3
- Version = '0.15.4'
3
+ Version = '0.15.5'
4
4
  end
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'