Module: Mongoid::Criteria::Queryable::Extensions::String::ClassMethods

Defined in:
build/mongoid-master/lib/mongoid/criteria/queryable/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#__expr_part__(key, value, negating = false) ⇒ Hash

Get the value as a expression.

Examples:

Get the value as an expression.

String.__expr_part__("field", value)

Parameters:

  • key (String, Symbol)

    The field key.

  • value (Object)

    The value of the criteria.

  • negating (true, false) (defaults to: false)

    If the selection should be negated.

Returns:

  • (Hash)

    The selection.



92
93
94
95
96
97
98
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/extensions/string.rb', line 92

def __expr_part__(key, value, negating = false)
  if negating
    { key => { "$#{value.regexp? ? "not" : "ne"}" => value }}
  else
    { key => value }
  end
end

#evolve(object) ⇒ String

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

Examples:

Evolve the string

String.evolve(1)

Parameters:

  • object (Object)

    The object to convert.

Returns:

  • (String)

    The value as a string.



109
110
111
112
113
# File 'build/mongoid-master/lib/mongoid/criteria/queryable/extensions/string.rb', line 109

def evolve(object)
  __evolve__(object) do |obj|
    obj.regexp? ? obj : obj.to_s
  end
end