Module: Mongoid::Matcher::EqImpl Private

Defined in:
build/mongoid-7.3/lib/mongoid/matcher/eq_impl.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.

This module is used by $eq and other operators that need to perform the matching that $eq performs (for example, $ne which negates the result of $eq). Unlike $eq this module takes an original operator as an additional argument to matches? to provide the correct exception messages reflecting the operator that was first invoked.

Class Method Summary collapse

Class Method Details

.matches?(exists, value, condition, original_operator) ⇒ Boolean

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:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'build/mongoid-7.3/lib/mongoid/matcher/eq_impl.rb', line 12

module_function def matches?(exists, value, condition, original_operator)
  case condition
  when Range
    # Since $ne invokes $eq, the exception message needs to handle
    # both operators.
    raise Errors::InvalidQuery, "Range is not supported as an argument to '#{original_operator}'"
=begin
    if value.is_a?(Array)
      value.any? { |elt| condition.include?(elt) }
    else
      condition.include?(value)
    end
=end
  else
    value == condition ||
    value.is_a?(Array) && value.include?(condition)
  end
end