diff --git a/lib/mongoid/extensions/string.rb b/lib/mongoid/extensions/string.rb index b2e028fe65..5624c7edce 100644 --- a/lib/mongoid/extensions/string.rb +++ b/lib/mongoid/extensions/string.rb @@ -63,6 +63,18 @@ 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. # diff --git a/lib/mongoid/extensions/symbol.rb b/lib/mongoid/extensions/symbol.rb index 36e48c68ba..c37536e965 100644 --- a/lib/mongoid/extensions/symbol.rb +++ b/lib/mongoid/extensions/symbol.rb @@ -7,6 +7,18 @@ 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