/
bits_all_clear.rb
41 lines (38 loc) · 1.06 KB
/
bits_all_clear.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
41
# rubocop:todo all
module Mongoid
module Matcher
# In-memory matcher for $bitsAllClear expression.
#
# @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/
#
# @api private
module BitsAllClear
include Bits
extend self
# Returns whether a position list condition matches a value.
#
# @param [ Object ] value The value to check.
# @param [ Array<Numeric> ] condition The position list condition.
#
# @return [ true | false ] Whether the value matches.
#
# @api private
def array_matches?(value, condition)
condition.all? do |c|
value & (1<<c) == 0
end
end
# Returns whether a bitmask condition matches a value.
#
# @param [ Object ] value The value to check.
# @param [ Numeric ] condition The bitmask condition.
#
# @return [ true | false ] Whether the value matches.
#
# @api private
def int_matches?(value, condition)
value & condition == 0
end
end
end
end