Module: Mongoid::Extensions::Regexp::ClassMethods

Defined in:
lib/mongoid/extensions/regexp.rb

Instance Method Summary collapse

Instance Method Details

#mongoize(object) ⇒ Regexp | nil Also known as: demongoize

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

Examples:

Mongoize the object.

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

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (Regexp | nil)

    The object mongoized or nil.



21
22
23
24
25
26
27
28
29
30
# 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