123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Defined in: lib/mongoid/extensions/regexp.rb

Instance Method Summary

Instance Method Details

#demongoize(object)

Alias for #mongoize.

[ GitHub ]

  
# File 'lib/mongoid/extensions/regexp.rb', line 31

alias :demongoize :mongoize

#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.

[ GitHub ]

  
# 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