模块:Mongoid::Matcher::Bits Private

包含在:
BitsAllClear, BitsAllSet, BitsAnyClear, BitsAnySet
定义于:
lib/mongoid/matcher/bits.rb

Overview

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

按位表达式匹配器中包含的 Mixin 模块。

类方法摘要折叠

实例方法摘要折叠

类方法详细信息

Operator_namestring

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

返回表达式操作符的名称。

返回:

  • ( string )

    操作符名称。



60
61
62
# File 'lib/mongoid/matcher/bits.rb', line 60

module_function def Operator_name
  名称.(/ .*:: /, ' ').(/ \A(.) /) { |l| l.Downcase }
end

实例方法详细信息

#matches?(_exists, value, condition) ⇒ true | false

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

返回值是否满足按位表达式。

参数:

  • 存在 ( true | false )

    未使用。

  • ( Object )

    要检查的值。

  • 条件 ( Numeric | Array<Numeric> )

    作为位掩码或位置列表的表达式谓词。

返回:

  • ( true | false )

    值是否匹配。



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
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mongoid/matcher/bits.rb', line 17

def 匹配?(_exists, , 条件)
  案例 
  when BSON::二进制文件
     = .数据.拆分(' ').map { |n| '%02x' % n.ord }.连接 (JOIN).to_i(16)
  end
  案例 条件
  when 阵列
    array_matches?(, 条件)
  when BSON::二进制文件
    int_cond = 条件.数据.拆分(' ').map { |n| '%02x' % n.ord }.连接 (JOIN).to_i(16)
    int_matches?(, int_cond)
  when 整型
    if 条件 < 0
      提高 Errors::InvalidQuery,
            " $ #{ operator_name } 参数 的值无效 :不允许使用负整数: #{ condition } "
    end

    int_matches?(, 条件)
  when Float
    # 允许整数 float(例如50.0),但拒绝那些
    # 带小数部分(例如50.1),因为按位操作需要整数。
    int_cond = 条件.to_i
    if int_cond == 条件
      if int_cond < 0
        提高 Errors::InvalidQuery,
              " $ #{ operator_name }参数的值无效:不允许使用负数: #{ condition } "
      end

      int_matches?(, int_cond)
    else
      提高 Errors::InvalidQuery,
            " $ #{ operator_name} 参数的 类型无效 :无法表示为整数: #{ condition} "
    end
  else
    提高 Errors::InvalidQuery, " $ #{ operator_name } 参数 的类型无效 : #{ condition } "
  end
end