module Mongoid::Criteria::Queryable::Extensions::String::ClassMethods

Public Instance Methods

__expr_part__(key, value, negating = false) click to toggle source

Get the value as a expression.

@example Get the value as an expression.

String.__expr_part__("field", value)

@param [ String | Symbol ] key The field key. @param [ Object ] value The value of the criteria. @param [ true | false ] negating If the selection should be negated.

@return [ Hash ] The selection.

# File lib/mongoid/criteria/queryable/extensions/string.rb, line 83
def __expr_part__(key, value, negating = false)
  if negating
    { key => { "$#{__regexp?(value) ? "not" : "ne"}" => value }}
  else
    { key => value }
  end
end
evolve(object) click to toggle source

Evolves the string into a MongoDB friendly value - in this case a string.

@example Evolve the string

String.evolve(1)

@param [ Object ] object The object to convert.

@return [ String ] The value as a string.

# File lib/mongoid/criteria/queryable/extensions/string.rb, line 100
def evolve(object)
  __evolve__(object) do |obj|
    __regexp?(obj) ? obj : obj.to_s
  end
end

Private Instance Methods

__regexp?(object) click to toggle source

Returns whether the object is Regexp-like.

@param [ Object ] object The object to evaluate.

@return [ Boolean ] Whether the object is Regexp-like.

# File lib/mongoid/criteria/queryable/extensions/string.rb, line 113
def __regexp?(object)
  object.is_a?(Regexp) || object.is_a?(BSON::Regexp::Raw)
end