module Mongoid::Matcher::FieldOperator

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

@api private

Constants

MAP

Public Instance Methods

apply_array_field_operator(exists, value, condition) { |v| ... } click to toggle source

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

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

@api private

# File lib/mongoid/matcher/field_operator.rb, line 54
                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) click to toggle source

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

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

@api private

# File lib/mongoid/matcher/field_operator.rb, line 67
                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) click to toggle source

Returns the matcher module for a given operator.

@param [ String ] op The operator name.

@return [ Module ] The matcher module.

@raises [ Mongoid::Errors::InvalidFieldOperator ]

Raised if the given operator is unknown.

@api private

# File lib/mongoid/matcher/field_operator.rb, line 43
                def get(op)
  MAP.fetch(op)
rescue KeyError
  raise Errors::InvalidFieldOperator.new(op)
end