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

Defined in:
build/mongoid-master/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.



18
19
20
21
22
23
24
25
26
27
# File 'build/mongoid-master/lib/mongoid/extensions/regexp.rb', line 18

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