模块:Mongoid::Matcher::Type Private

定义于:
lib/mongoid/matcher/type.rb

Overview

该模块是私有 API 的一部分。 您应尽可能避免使用此模块,因为它将来可能会被删除或更改。

$type 表达式的内存中匹配器。

类方法摘要折叠

类方法详细信息

。匹配? (exists, value, Condition) ⇒ true | false ,布尔值

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回一个值是否满足 $type表达式。

参数:

  • 存在 ( true | false ) —

    值是否存在。

  • 值 ( Object ) —

    要检查的值。

  • 条件 ( Integer | Array<Integer> ) —

    对应于BSON类型枚举的 $type 条件谓词。

返回:

  • ( true | false ) —

    值是否匹配。

  • (布尔值)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mongoid/matcher/type.rb', line 19

module_function def 匹配?(存在, 值, 条件)
  条件 = 案例 条件
               when 阵列
                 条件
               when 整型
                 [ 条件 ]
               else
                 提高 Errors::InvalidQuery, "未知的 $type 参数: #{ condition } "
               end
  条件.每 do |条件|
    return true if one_matches?(存在, 值, 条件)
  end
  false
end

。 one_matches? (exists, value, Condition) ⇒ true | false ,布尔值

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回一个值是否满足单个 $type表达式值。

参数:

  • 存在 ( true | false ) —

    值是否存在。

  • 值 ( Object ) —

    要检查的值。

  • 条件 ( Integer ) —

    对应于BSON类型枚举的 $type 条件谓词。

返回:

  • ( true | false ) —

    值是否匹配。

  • (布尔值)


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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mongoid/matcher/type.rb', line 45

module_function def one_matches?(存在, 值, 条件)
  案例 条件
  when 1
    # Double
    值.is_a?(Float)
  when 2
    # string
    值.is_a?(字符串)
  when 3
    # 对象
    值.is_a?(哈希)
  when 4
    # 数组
    值.is_a?(阵列)
  when 5
    # 二进制数据
    值.is_a?(BSON::二进制文件)
  when 6
    # Undefined
    值.is_a?(BSON::未定义)
  when 7
    # ObjectId
    值.is_a?(BSON::ObjectId)
  when 8
    # 布尔值
    值.is_a?(TrueClass) || 值.is_a?(FalseClass)
  when 9
    # 日期
    值.is_a?(Date) || 值.is_a?(时间) || 值.is_a?(日期时间)
  when 10
    # Null
    存在 && 值.is_a?(NilClass)
  when 11
    # 正则表达式
    值.is_a?(regexp::原始) || 值.is_a?(::regexp)
  when 12
    # DBPointer 已弃用
    值.is_a?(BSON::数据库指针)
  when 13
    # JavaScript
    值.is_a?(BSON::代码)
  when 14
    # 符号已弃用
    值.is_a?(符号) || 值.is_a?(BSON::符号::原始)
  when 15
    # 含已弃用代码的JavaScript
    值.is_a?(BSON::CodeWithScope)
  when 16
    # 32位整型
    值.is_a?(BSON::Int32) || (值.is_a?(整型) && (-2**32..(2**32) - 1).包括?(值))
  when 17
    # 时间戳
    值.is_a?(BSON::时间戳)
  when 18
    # Long
    值.is_a?(BSON::Int64) ||
      (值.is_a?(整型) &&
        (-2**64..(2**64) - 1).包括?(值) &&
        !(-2**32..(2**32) - 1).包括?(值))
  when 19
    # Decimal
    值.is_a?(BSON::Decimal128)
  when -1
    # minKey
    值.is_a?(BSON::最小键值)
  when 127
    # maxKey
    值.is_a?(BSON::Max key)
  else
    提高 Errors::InvalidQuery, "未知的 $type 参数: #{ condition } "
  end
end