module Mongoid::Extensions::Regexp::ClassMethods

Public Instance Methods

demongoize(object)
Alias for: mongoize
mongoize(object) click to toggle source

Turn the object from the ruby type we deal with to a Mongo friendly type.

@example Mongoize the object.

Regexp.mongoize(/\A[abc]/)

@param [ Object ] object The object to mongoize.

@return [ Regexp | nil ] The object mongoized or nil.

# File lib/mongoid/extensions/regexp.rb, line 21
def mongoize(object)
  return if object.nil?
  case object
  when String then ::Regexp.new(object)
  when ::Regexp then object
  when BSON::Regexp::Raw then object.compile
  end
rescue RegexpError
  nil
end
Also aliased as: demongoize