/
in.rb
40 lines (38 loc) · 1.11 KB
/
in.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# rubocop:todo all
module Mongoid
module Matcher
# In-memory matcher for $in expression.
#
# @see https://www.mongodb.com/docs/manual/reference/operator/query/in/
#
# @api private
module In
# Returns whether a value satisfies an $in expression.
#
# @param [ true | false ] exists Not used.
# @param [ Object ] value The value to check.
# @param [ Array<Object> ] condition The $in condition predicate.
#
# @return [ true | false ] Whether the value matches.
#
# @api private
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
end
end
end