Module: Mongoid::Matcher::In Private

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

In-memory matcher for $in expression.

Class Method Summary collapse

Class Method Details

.matches?(exists, value, condition) ⇒ true | false, 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 whether a value satisfies an $in expression.

Parameters:

  • exists (true | false)

    Not used.

  • value (Object)

    The value to check.

  • condition (Array<Object>)

    The $in condition predicate.

Returns:

  • (true | false)

    Whether the value matches.

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mongoid/matcher/in.rb', line 21

module_function def matches?(exists, value, condition)
  unless Array === condition
    raise Errors::InvalidQuery, "$in argument must be an array: #{Errors::InvalidQuery.truncate_expr(condition)}"
  end
  if Array === value
    if value.any? { |v|
      condition.any? do |c|
        EqImplWithRegexp.matches?('$in', v, c)
      end
    } then
      return true
    end
  end
  condition.any? do |c|
    EqImplWithRegexp.matches?('$in', value, c)
  end
end