Module: Mongoid::Matcher::FieldOperator Private

Defined in:
lib/mongoid/matcher/field_operator.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Singleton module provides lookup of query operator matchers related to field values.

API:

  • private

Constant Summary collapse

MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

{
  '$all' => All,
  '$bitsAllClear' => BitsAllClear,
  '$bitsAllSet' => BitsAllSet,
  '$bitsAnyClear' => BitsAnyClear,
  '$bitsAnySet' => BitsAnySet,
  '$elemMatch' => ElemMatch,
  '$eq' => Eq,
  '$exists' => Exists,
  '$gt' => Gt,
  '$gte' => Gte,
  '$in' => In,
  '$lt' => Lt,
  '$lte' => Lte,
  '$mod' => Mod,
  '$nin' => Nin,
  '$ne' => Ne,
  '$not' => Not,
  '$regex' => Regex,
  '$size' => Size,
  '$type' => Type,
}.freeze

Class Method Summary collapse

Class Method Details

.apply_array_field_operator(exists, value, condition) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

Refactor this as it is only relevant to $lt, $lte, $gt, $gte.

Used for evaluating $lt, $lte, $gt, $gte comparison operators.

API:

  • private

  • private



54
55
56
57
58
59
60
# File 'lib/mongoid/matcher/field_operator.rb', line 54

module_function def apply_array_field_operator(exists, value, condition)
  if Array === value
    value.any? { |v| yield v }
  else
    yield value
  end
end

.apply_comparison_operator(operator, left, right) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

Refactor this as it is only relevant to $lt, $lte, $gt, $gte.

Used for evaluating $lt, $lte, $gt, $gte comparison operators.

API:

  • private

  • private



67
68
69
70
71
72
73
74
75
# File 'lib/mongoid/matcher/field_operator.rb', line 67

module_function def apply_comparison_operator(operator, left, right)
  left.send(operator, right)
rescue ArgumentError, NoMethodError, TypeError
  # We silence bogus comparison attempts, e.g. number to string
  # comparisons.
  # Several different exceptions may be produced depending on the types
  # involved.
  false
end

.get(op) ⇒ Module

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the matcher module for a given operator.

Parameters:

  • The operator name.

Returns:

  • The matcher module.

API:

  • private

  • private



43
44
45
46
47
# File 'lib/mongoid/matcher/field_operator.rb', line 43

module_function def get(op)
  MAP.fetch(op)
rescue KeyError
  raise Errors::InvalidFieldOperator.new(op)
end