123456789_123456789_123456789_123456789_123456789_

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

Overview

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

Examples:

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.

Examples:

Convert all the values to arrays.

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

Parameters:

  • criterion (Hash)

    The criterion.

Returns:

  • (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'
  end

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

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

Parameters:

  • field (String | Symbol | Key)

    The field to expand.

  • value (Object)

    The field’s value.

Returns:

  • (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]
end