123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Defined in: lib/mongoid/criteria/queryable/extensions/string.rb

Instance Method Summary

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.

[ GitHub ]

  
# 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

#__regexp?(object) ⇒ Boolean (private)

Returns whether the object is Regexp-like.

Parameters:

  • object (Object)

    The object to evaluate.

Returns:

  • (Boolean)

    Whether the object is Regexp-like.

[ GitHub ]

  
# File 'lib/mongoid/criteria/queryable/extensions/string.rb', line 113

def __regexp?(object)
  object.is_a?(Regexp) || object.is_a?(BSON::Regexp::Raw)
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.

[ GitHub ]

  
# 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