模块: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 )

    值是否匹配。

  • 布尔值


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

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

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

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

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

参数:

  • 存在 ( true | false )

    值是否存在。

  • ( Object )

    要检查的值。

  • 条件 ( Integer )

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

返回:

  • ( true | false )

    值是否匹配。

  • 布尔值


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
117
118
119
120
121
# File 'lib/mongoid/matcher/type.rb', line 50

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