Module: Mongoid::Criteria::Queryable::Expandable Private

Do not use. This module is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/mongoid/criteria/queryable/expandable.rb


This module encapsulates methods that expand various high level query forms to the MongoDB hash condition selector syntax.


Example high level form.

Band.where(:foo.gt => 5)

Instance Method Summary

Instance Method Details

#expand_condition_to_array_values(criterion) ⇒ Hash (private)

Expand criterion values to arrays, to be used with operators that take an array as argument such as $in.


Convert all the values to arrays.

selectable.with_array_values({ key: 1...4 })


  • criterion (Hash)

    The criterion.


  • (Hash)

    The $in friendly criterion with array values.

[ GitHub ]

# File 'lib/mongoid/criteria/queryable/expandable.rb', line 56

def expand_condition_to_array_values(criterion)
  if criterion.nil?
    raise ArgumentError, 'Criterion cannot be nil here'

  Hash[criterion.map do |key, value|
    [key, value.__array__]

#expand_one_condition(field, value) ⇒ Array<String, Object> (private)

Expands the specified condition to MongoDB syntax.

This method is meant to be called when processing the items of a condition hash and the key and the value of each item are already available separately.

The following parameter forms are accepted:

  • field is a string or symbol; value is the field query expresision

  • field is a Key instance; value is the field query expression

  • field is a string corresponding to a MongoDB operator; value is the operator value expression.

This method expands the field-value combination to the MongoDB selector syntax and returns an array of [expanded key, expanded value]. The expanded key is converted to a string if it wasn’t already a string.


  • field (String | Symbol | Key)

    The field to expand.

  • value (Object)

    The field’s value.


  • (Array<String, Object>)

    The expanded field and value.

[ GitHub ]

# File 'lib/mongoid/criteria/queryable/expandable.rb', line 40

def expand_one_condition(field, value)
  kv = field.__expr_part__(value.__expand_complex__, negating?)
  [kv.keys.first.to_s, kv.values.first]