diff --git a/docs/release-notes/mongoid-9.0.txt b/docs/release-notes/mongoid-9.0.txt index 653eb4dc20..89f6b6b55a 100644 --- a/docs/release-notes/mongoid-9.0.txt +++ b/docs/release-notes/mongoid-9.0.txt @@ -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 ----------------------------------------- diff --git a/lib/mongoid/criteria.rb b/lib/mongoid/criteria.rb index ca024cace9..5e4442cfba 100644 --- a/lib/mongoid/criteria.rb +++ b/lib/mongoid/criteria.rb @@ -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. diff --git a/lib/mongoid/criteria/queryable/extensions/object.rb b/lib/mongoid/criteria/queryable/extensions/object.rb index 32605781d4..831ad7c3f1 100644 --- a/lib/mongoid/criteria/queryable/extensions/object.rb +++ b/lib/mongoid/criteria/queryable/extensions/object.rb @@ -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. diff --git a/lib/mongoid/criteria/queryable/extensions/regexp.rb b/lib/mongoid/criteria/queryable/extensions/regexp.rb index 514c564b26..57ba30639b 100644 --- a/lib/mongoid/criteria/queryable/extensions/regexp.rb +++ b/lib/mongoid/criteria/queryable/extensions/regexp.rb @@ -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. @@ -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. diff --git a/lib/mongoid/extensions/array.rb b/lib/mongoid/extensions/array.rb index 0cf2a92d14..9639218c66 100644 --- a/lib/mongoid/extensions/array.rb +++ b/lib/mongoid/extensions/array.rb @@ -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. @@ -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. # @@ -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. # diff --git a/lib/mongoid/extensions/big_decimal.rb b/lib/mongoid/extensions/big_decimal.rb index cce430f2bc..f837d2f4f8 100644 --- a/lib/mongoid/extensions/big_decimal.rb +++ b/lib/mongoid/extensions/big_decimal.rb @@ -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. # diff --git a/lib/mongoid/extensions/false_class.rb b/lib/mongoid/extensions/false_class.rb index d50e6a6b9d..30cc0df6a1 100644 --- a/lib/mongoid/extensions/false_class.rb +++ b/lib/mongoid/extensions/false_class.rb @@ -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? diff --git a/lib/mongoid/extensions/hash.rb b/lib/mongoid/extensions/hash.rb index 19aaef11af..a686645533 100644 --- a/lib/mongoid/extensions/hash.rb +++ b/lib/mongoid/extensions/hash.rb @@ -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. # @@ -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 diff --git a/lib/mongoid/extensions/integer.rb b/lib/mongoid/extensions/integer.rb index ec35ee97bd..3ea61b17f4 100644 --- a/lib/mongoid/extensions/integer.rb +++ b/lib/mongoid/extensions/integer.rb @@ -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 diff --git a/lib/mongoid/extensions/nil_class.rb b/lib/mongoid/extensions/nil_class.rb index 7cfc52a951..10dc3872ad 100644 --- a/lib/mongoid/extensions/nil_class.rb +++ b/lib/mongoid/extensions/nil_class.rb @@ -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. diff --git a/lib/mongoid/extensions/object.rb b/lib/mongoid/extensions/object.rb index 67b91bc987..baa865af41 100644 --- a/lib/mongoid/extensions/object.rb +++ b/lib/mongoid/extensions/object.rb @@ -20,71 +20,6 @@ def __evolve_object_id__ end alias :__mongoize_object_id__ :__evolve_object_id__ - # Convert the object to args for a find query. - # - # @example Convert the object to args. - # object.__find_args__ - # - # @return [ Object ] self. - # @deprecated - def __find_args__ - self - end - Mongoid.deprecate(self, :__find_args__) - - # Try to form a setter from this object. - # - # @example Try to form a setter. - # object.__setter__ - # - # @return [ String ] The object as a string plus =. - # @deprecated - def __setter__ - "#{self}=" - end - Mongoid.deprecate(self, :__setter__) - - # Get the value of the object as a mongo friendly sort value. - # - # @example Get the object as sort criteria. - # object.__sortable__ - # - # @return [ Object ] self. - # @deprecated - def __sortable__ - self - end - Mongoid.deprecate(self, :__sortable__) - - # Conversion of an object to an $inc-able value. - # - # @example Convert the object. - # 1.__to_inc__ - # - # @return [ Object ] The object. - # @deprecated - def __to_inc__ - self - end - Mongoid.deprecate(self, :__to_inc__) - - - # Do or do not, there is no try. -- Yoda. - # - # @example Do or do not. - # object.do_or_do_not(:use, "The Force") - # - # @param [ String | Symbol ] name The method name. - # @param [ Object... ] *args The arguments. - # - # @return [ Object | nil ] The result of the method call or nil if the - # method does not exist. - # @deprecated - def do_or_do_not(name, *args) - send(name, *args) if name && respond_to?(name) - end - Mongoid.deprecate(self, :do_or_do_not) - # Get the value for an instance variable or false if it doesn't exist. # # @example Get the value for an instance var. @@ -113,18 +48,6 @@ def mongoize self end - # Is the object multi args. - # - # @example Is the object multi args? - # object.multi_arged? - # - # @return [ false ] false. - # @deprecated - def multi_arged? - false - end - Mongoid.deprecate(self, :multi_arged?) - # Is the object a number? # # @example Is the object a number?. @@ -172,40 +95,7 @@ def substitutable self end - # You must unlearn what you have learned. -- Yoda - # - # @example You must perform this execution. - # object.you_must(:use, "The Force") - # - # @param [ String | Symbol ] name The method name. - # @param [ Object... ] *args The arguments. - # - # @return [ Object | nil ] The result of the method call or nil if the - # method does not exist. Nil if the object is frozen. - # @deprecated - def you_must(name, *args) - frozen? ? nil : do_or_do_not(name, *args) - end - Mongoid.deprecate(self, :you_must) - module ClassMethods - # Convert the provided object to a foreign key, given the metadata key - # contstraint. - # - # @example Convert the object to a fk. - # Object.__mongoize_fk__(association, object) - # - # @param [ Mongoid::Association::Relatable ] association The association metadata. - # @param [ Object ] object The object to convert. - # - # @return [ Object ] The converted object. - # @deprecated - def __mongoize_fk__(association, object) - return nil if !object || object == "" - association.convert_to_foreign_key(object) - end - Mongoid.deprecate(self, :__mongoize_fk__) - # Convert the object from its mongo friendly ruby type to this type. # # @example Demongoize the object. diff --git a/lib/mongoid/extensions/range.rb b/lib/mongoid/extensions/range.rb index 190bd8aa81..1d480016e0 100644 --- a/lib/mongoid/extensions/range.rb +++ b/lib/mongoid/extensions/range.rb @@ -9,18 +9,6 @@ def self.included(base) base.extend(ClassMethods) end - # Get the range as arguments for a find. - # - # @example Get the range as find args. - # range.__find_args__ - # - # @return [ Array ] The range as an array. - # @deprecated - def __find_args__ - to_a - end - Mongoid.deprecate(self, :__find_args__) - # Turn the object from the ruby type we deal with to a Mongo friendly # type. # diff --git a/lib/mongoid/extensions/string.rb b/lib/mongoid/extensions/string.rb index b541b3adc9..be60d07f20 100644 --- a/lib/mongoid/extensions/string.rb +++ b/lib/mongoid/extensions/string.rb @@ -7,11 +7,6 @@ module Extensions # Adds type-casting behavior to String class. module String - # @attribute [rw] unconvertable_to_bson If the document is unconvertable. - # @deprecated - attr_accessor :unconvertable_to_bson - Mongoid.deprecate(self, :unconvertable_to_bson, :unconvertable_to_bson=) - # Evolve the string into an object id if possible. # # @example Evolve the string. @@ -63,18 +58,6 @@ def collectionize tableize.gsub("/", "_") end - # Is the string a valid value for a Mongoid id? - # - # @example Is the string an id value? - # "_id".mongoid_id? - # - # @return [ true | false ] If the string is id or _id. - # @deprecated - def mongoid_id? - self =~ /\A(|_)id\z/ - end - Mongoid.deprecate(self, :mongoid_id?) - # Is the string a number? The literals "NaN", "Infinity", and "-Infinity" # are counted as numbers. # @@ -128,19 +111,6 @@ def before_type_cast? ends_with?("_before_type_cast") end - - # Is the object not to be converted to bson on criteria creation? - # - # @example Is the object unconvertable? - # object.unconvertable_to_bson? - # - # @return [ true | false ] If the object is unconvertable. - # @deprecated - def unconvertable_to_bson? - @unconvertable_to_bson ||= false - end - Mongoid.deprecate(self, :unconvertable_to_bson?) - private # If the string is a legal object id, convert it. diff --git a/lib/mongoid/extensions/symbol.rb b/lib/mongoid/extensions/symbol.rb index c37536e965..36e48c68ba 100644 --- a/lib/mongoid/extensions/symbol.rb +++ b/lib/mongoid/extensions/symbol.rb @@ -7,18 +7,6 @@ module Extensions # Adds type-casting behavior to Symbol class. module Symbol - # Is the symbol a valid value for a Mongoid id? - # - # @example Is the string an id value? - # :_id.mongoid_id? - # - # @return [ true | false ] If the symbol is :id or :_id. - # @deprecated - def mongoid_id? - to_s.mongoid_id? - end - Mongoid.deprecate(self, :mongoid_id?) - module ClassMethods # Turn the object from the ruby type we deal with to a Mongo friendly diff --git a/lib/mongoid/extensions/true_class.rb b/lib/mongoid/extensions/true_class.rb index 779586c743..029dcf31ae 100644 --- a/lib/mongoid/extensions/true_class.rb +++ b/lib/mongoid/extensions/true_class.rb @@ -5,17 +5,6 @@ module Mongoid module Extensions # Adds type-casting behavior to TrueClass module TrueClass - # Get the value of the object as a mongo friendly sort value. - # - # @example Get the object as sort criteria. - # object.__sortable__ - # - # @return [ Integer ] 1. - # @deprecated - def __sortable__ - 1 - end - Mongoid.deprecate(self, :__sortable__) # Is the passed value a boolean? #