Module: Mongoid::Criteria::Queryable::Expandable Private
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.
Instance Method Summary
-
#expand_condition_to_array_values(criterion) ⇒ Hash
private
Internal use only
Expand criterion values to arrays, to be used with operators that take an array as argument such as $in.
-
#expand_one_condition(field, value) ⇒ Array<String, Object>
private
Internal use only
Expands the specified condition to MongoDB syntax.
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.
# File 'lib/mongoid/criteria/queryable/expandable.rb', line 56
def (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.
# File 'lib/mongoid/criteria/queryable/expandable.rb', line 40
def (field, value) kv = field.__expr_part__(value., negating?) [kv.keys.first.to_s, kv.values.first] end