Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5660: Remove deprecated monkey-patch methods (merge in Mongoid 10.x) #5745

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/release-notes/mongoid-9.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,33 @@ Deprecated functionality removed
- The deprecated class ``Mongoid::Errors::InvalidStorageParent`` has been removed.


Deprecated kernel monkey patch methods removed
----------------------------------------------

The following kernel monkey patch methods are removed. These were previously deprecated and were intended
for internal Mongoid use only, so please refer to the Mongoid 8.x codebase for the implementation if
you were using them.

- ``Object#__sortable__``
- ``Object#__find_args__``
- ``Object#__setter__``
- ``Object#__to_inc__``
- ``Object#do_or_do_not``
- ``Object#you_must``
- ``Object#multi_arged?``
- ``Object#regexp?``
- ``Object.__mongoize_fk__``
- ``Hash#__consolidate__``
- ``Hash#delete_id``
- ``Hash#extract_id``
- ``Hash#to_criteria``
- ``Mongoid::Criteria#to_criteria``
- ``Integer#unconvertable_to_bson?``
- ``String#unconvertable_to_bson?``
- ``String#mongoid_id?``
- ``Symbol#mongoid_id?``


``touch`` method now clears changed state
-----------------------------------------

Expand Down
12 changes: 0 additions & 12 deletions lib/mongoid/criteria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,6 @@ def respond_to?(name, include_private = false)

alias :to_ary :to_a

# Convenience for objects that want to be merged into a criteria.
#
# @example Convert to a criteria.
# criteria.to_criteria
#
# @return [ Criteria ] self.
# @deprecated
def to_criteria
self
end
Mongoid.deprecate(self, :to_criteria)

# Convert the criteria to a proc.
#
# @example Convert the criteria to a proc.
Expand Down
12 changes: 0 additions & 12 deletions lib/mongoid/criteria/queryable/extensions/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,6 @@ def __expand_complex__
self
end

# Is the object a regex.
#
# @example Is the object a regex?
# obj.regexp?
#
# @return [ false ] Always false.
# @deprecated
def regexp?
false
end
Mongoid.deprecate(self, :regexp?)

module ClassMethods

# Evolve the object.
Expand Down
20 changes: 0 additions & 20 deletions lib/mongoid/criteria/queryable/extensions/regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ module Extensions
# Adds query type-casting behavior to Regexp class.
module Regexp

# Is the object a regexp?
#
# @example Is the object a regex?
# /\A[123]/.regexp?
#
# @return [ true ] Always true.
# @deprecated
def regexp?; true; end
Mongoid.deprecate(self, :regexp?)

module ClassMethods

# Evolve the object into a regex.
Expand All @@ -39,16 +29,6 @@ def evolve(object)
# Adds query type-casting behavior to BSON::Regexp::Raw class.
module Raw_

# Is the object a regexp?
#
# @example Is the object a regex?
# bson_raw_regexp.regexp?
#
# @return [ true ] Always true.
# @deprecated
def regexp?; true; end
Mongoid.deprecate(self, :regexp?)

module ClassMethods

# Evolve the object into a raw bson regex.
Expand Down
43 changes: 0 additions & 43 deletions lib/mongoid/extensions/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ def __evolve_object_id__
self
end

# Get the array of args as arguments for a find query.
#
# @example Get the array as find args.
# [ 1, 2, 3 ].__find_args__
#
# @return [ Array ] The array of args.
# @deprecated
def __find_args__
flat_map{ |a| a.__find_args__ }.uniq{ |a| a.to_s }
end
Mongoid.deprecate(self, :__find_args__)

# Mongoize the array into an array of object ids.
#
# @example Evolve the array to object ids.
Expand All @@ -55,18 +43,6 @@ def __mongoize_time__
::Time.zone.local(*self)
end

# Is the array a set of multiple arguments in a method?
#
# @example Is this multi args?
# [ 1, 2, 3 ].multi_arged?
#
# @return [ true | false ] If the array is multi args.
# @deprecated
def multi_arged?
!first.is_a?(Hash) && first.resizable? || size > 1
end
Mongoid.deprecate(self, :multi_arged?)

# Turn the object from the ruby type we deal with to a Mongo friendly
# type.
#
Expand Down Expand Up @@ -105,25 +81,6 @@ def resizable?

module ClassMethods

# Convert the provided object to a proper array of foreign keys.
#
# @example Mongoize the object.
# Array.__mongoize_fk__(constraint, object)
#
# @param [ Mongoid::Association::Relatable ] association The association metadata.
# @param [ Object ] object The object to convert.
#
# @return [ Array ] The array of ids.
# @deprecated
def __mongoize_fk__(association, object)
if object.resizable?
object.blank? ? object : association.convert_to_foreign_key(object)
else
object.blank? ? [] : association.convert_to_foreign_key(Array(object))
end
end
Mongoid.deprecate(self, :__mongoize_fk__)

# Turn the object from the ruby type we deal with to a Mongo friendly
# type.
#
Expand Down
12 changes: 0 additions & 12 deletions lib/mongoid/extensions/big_decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ def self.included(base)
base.extend(ClassMethods)
end

# Convert the big decimal to an $inc-able value.
#
# @example Convert the big decimal.
# bd.__to_inc__
#
# @return [ Float ] The big decimal as a float.
# @deprecated
def __to_inc__
to_f
end
Mongoid.deprecate(self, :__to_inc__)

# Turn the object from the ruby type we deal with to a Mongo friendly
# type.
#
Expand Down
12 changes: 0 additions & 12 deletions lib/mongoid/extensions/false_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ module Mongoid
module Extensions
# Adds type-casting behavior to FalseClass.
module FalseClass
# Get the value of the object as a mongo friendly sort value.
#
# @example Get the object as sort criteria.
# object.__sortable__
#
# @return [ Integer ] 0.
# @deprecated
def __sortable__
0
end
Mongoid.deprecate(self, :__sortable__)

# Is the passed value a boolean?
#
# @example Is the value a boolean type?
Expand Down
55 changes: 0 additions & 55 deletions lib/mongoid/extensions/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,6 @@ def __mongoize_object_id__
end
end

# Consolidate the key/values in the hash under an atomic $set.
# DEPRECATED. This was never intended to be a public API and
# the functionality will no longer be exposed once this method
# is eventually removed.
#
# @example Consolidate the hash.
# { name: "Placebo" }.__consolidate__
#
# @return [ Hash ] A new consolidated hash.
#
# @deprecated
def __consolidate__(klass)
Mongoid::AtomicUpdatePreparer.prepare(self, klass)
end
Mongoid.deprecate(self, :__consolidate__)

# Deletes an id value from the hash.
#
# @example Delete an id value.
# {}.delete_id
#
# @return [ Object ] The deleted value, or nil.
# @deprecated
def delete_id
delete("_id") || delete(:_id) || delete("id") || delete(:id)
end
Mongoid.deprecate(self, :delete_id)

# Get the id attribute from this hash, whether it's prefixed with an
# underscore or is a symbol.
#
# @example Extract the id.
# { :_id => 1 }.extract_id
#
# @return [ Object ] The value of the id.
# @deprecated
def extract_id
self["_id"] || self[:_id] || self["id"] || self[:id]
end
Mongoid.deprecate(self, :extract_id)

# Turn the object from the ruby type we deal with to a Mongo friendly
# type.
#
Expand All @@ -93,20 +52,6 @@ def resizable?
true
end

# Convert this hash to a criteria. Will iterate over each keys in the
# hash which must correspond to method on a criteria object. The hash
# must also include a "klass" key.
#
# @example Convert the hash to a criteria.
# { klass: Band, where: { name: "Depeche Mode" }.to_criteria
#
# @return [ Criteria ] The criteria.
# @deprecated
def to_criteria
Criteria.from_hash(self)
end
Mongoid.deprecate(self, :to_criteria)

private

module ClassMethods
Expand Down
12 changes: 0 additions & 12 deletions lib/mongoid/extensions/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ def numeric?
true
end

# Is the object not to be converted to bson on criteria creation?
#
# @example Is the object unconvertable?
# object.unconvertable_to_bson?
#
# @return [ true ] If the object is unconvertable.
# @deprecated
def unconvertable_to_bson?
true
end
Mongoid.deprecate(self, :unconvertable_to_bson?)

module ClassMethods

# Turn the object from the ruby type we deal with to a Mongo friendly
Expand Down
12 changes: 0 additions & 12 deletions lib/mongoid/extensions/nil_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ module Mongoid
module Extensions
# Adds type-casting behavior to NilClass.
module NilClass
# Try to form a setter from this object.
#
# @example Try to form a setter.
# object.__setter__
#
# @return [ nil ] Always nil.
# @deprecated
def __setter__
self
end
Mongoid.deprecate(self, :__setter__)

# Get the name of a nil collection.
#
# @example Get the nil name.
Expand Down
Loading
Loading