@@ -32,31 +32,20 @@ def __mongoize_object_id__
3232 end
3333
3434 # Consolidate the key/values in the hash under an atomic $set.
35+ # DEPRECATED. This was never intended to be a public API and
36+ # the functionality will no longer be exposed once this method
37+ # is eventually removed.
3538 #
3639 # @example Consolidate the hash.
3740 # { name: "Placebo" }.__consolidate__
3841 #
3942 # @return [ Hash ] A new consolidated hash.
43+ #
44+ # @deprecated
4045 def __consolidate__ ( klass )
41- consolidated = { }
42- each_pair do |key , value |
43- if key =~ /\$ /
44- value . keys . each do |key2 |
45- value2 = value [ key2 ]
46- real_key = klass . database_field_name ( key2 )
47-
48- value . delete ( key2 ) if real_key != key2
49- value [ real_key ] = value_for ( key , klass , real_key , value2 )
50- end
51- consolidated [ key ] ||= { }
52- consolidated [ key ] . update ( value )
53- else
54- consolidated [ "$set" ] ||= { }
55- consolidated [ "$set" ] . update ( key => mongoize_for ( key , klass , key , value ) )
56- end
57- end
58- consolidated
46+ Mongoid ::AtomicUpdatePreparer . prepare ( self , klass )
5947 end
48+ Mongoid . deprecate ( self , :__consolidate__ )
6049
6150 # Checks whether conditions given in this hash are known to be
6251 # unsatisfiable, i.e., querying with this hash will always return no
@@ -166,50 +155,6 @@ def to_criteria
166155
167156 private
168157
169- # Get the value for the provided operator, klass, key and value.
170- #
171- # This is necessary for special cases like $rename, $addToSet and $push.
172- #
173- # @param [ String ] operator The operator.
174- # @param [ Class ] klass The model class.
175- # @param [ String | Symbol ] key The field key.
176- # @param [ Object ] value The original value.
177- #
178- # @return [ Object ] Value prepared for the provided operator.
179- def value_for ( operator , klass , key , value )
180- case operator
181- when "$rename" then value . to_s
182- when "$addToSet" , "$push" then value . mongoize
183- else mongoize_for ( operator , klass , operator , value )
184- end
185- end
186-
187- # Mongoize for the klass, key and value.
188- #
189- # @api private
190- #
191- # @example Mongoize for the klass, field and value.
192- # {}.mongoize_for("$push", Band, "name", "test")
193- #
194- # @param [ String ] operator The operator.
195- # @param [ Class ] klass The model class.
196- # @param [ String | Symbol ] key The field key.
197- # @param [ Object ] value The value to mongoize.
198- #
199- # @return [ Object ] The mongoized value.
200- def mongoize_for ( operator , klass , key , value )
201- field = klass . fields [ key . to_s ]
202- if field
203- val = field . mongoize ( value )
204- if Mongoid ::Persistable ::LIST_OPERATIONS . include? ( operator ) && field . resizable?
205- val = val . first if !value . is_a? ( Array )
206- end
207- val
208- else
209- value
210- end
211- end
212-
213158 module ClassMethods
214159
215160 # Turn the object from the ruby type we deal with to a Mongo friendly
0 commit comments