Module: Mongoid::Matcher::Type Private

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

Class Method Summary collapse

Class Method Details

.matches?(exists, value, condition) ⇒ 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:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'build/mongoid-7.3/lib/mongoid/matcher/type.rb', line 8

module_function def matches?(exists, value, condition)
  conditions = case condition
  when Array
    condition
  when Integer
    [condition]
  else
    raise Errors::InvalidQuery, "Unknown $type argument: #{condition}"
  end
  conditions.each do |condition|
    if one_matches?(exists, value, condition)
      return true
    end
  end
  false
end

.one_matches?(exists, value, condition) ⇒ 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:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'build/mongoid-7.3/lib/mongoid/matcher/type.rb', line 25

module_function def one_matches?(exists, value, condition)
  case condition
  when 1
    # Double
    Float === value
  when 2
    # String
    String === value
  when 3
    # Object
    Hash === value
  when 4
    # Array
    Array === value
  when 5
    # Binary data
    BSON::Binary === value
  when 6
    # Undefined
    BSON::Undefined === value
  when 7
    # ObjectId
    BSON::ObjectId === value
  when 8
    # Boolean
    TrueClass === value || FalseClass === value
  when 9
    # Date
    Date === value || Time === value || DateTime === value
  when 10
    # Null
    exists && NilClass === value
  when 11
    # Regex
    Regexp::Raw === value || ::Regexp === value
  when 12
    # DBPointer deprecated
    BSON::DbPointer === value
  when 13
    # JavaScript
    BSON::Code === value
  when 14
    # Symbol deprecated
    Symbol === value || BSON::Symbol::Raw === value
  when 15
    # Javascript with code deprecated
    BSON::CodeWithScope === value
  when 16
    # 32-bit int
    BSON::Int32 === value || Integer === value && (-2**32..2**32-1).include?(value)
  when 17
    # Timestamp
    BSON::Timestamp === value
  when 18
    # Long
    BSON::Int64 === value ||
      Integer === value &&
        (-2**64..2**64-1).include?(value) &&
        !(-2**32..2**32-1).include?(value)
  when 19
    # Decimal
    BSON::Decimal128 === value
  when -1
    # minKey
    BSON::MinKey === value
  when 127
    # maxKey
    BSON::MaxKey === value
  else
    raise Errors::InvalidQuery, "Unknown $type argument: #{condition}"
  end
end