模块:Mongo::Lint Private

定义于:
lib/mongo/lint.rb

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

类方法摘要折叠

类方法详细信息

assert_type (obj, cls) ⇒对象

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

如果obj不是cls类型,则引发 LintError。

引发:



7
8
9
10
11
12
# File 'lib/ Mongo/lint.rb', 第 7 行

def assert_type(obj, cls)
  return 除非 已启用?
  return if obj.is_a?(cls)

  提高 错误::LintError, "应将#{ obj }#{ cls } "
end

已启用?布尔

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

返回:

  • 布尔值


94
95
96
# File 'lib/ Mongo/lint.rb', 第 94 行

def 已启用?
  ENV['MONGO_RUBY_DRIVER_LINT'] && %w[1  true ].包括?(ENV['MONGO_RUBY_DRIVER_LINT'].Downcase)
end

validate_camel_case_read_preference (read_pref) ⇒对象

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

引发:



34
35
36
37
38
39
40
# File 'lib/ Mongo/lint.rb', 第 34 行

def validate_camel_case_read_preference(read_pref)
  return 除非 已启用?
  return if read_pref.nil?
  提高 错误::LintError, "读取偏好不是哈希值: #{ read_pref } " 除非 read_pref.is_a?(哈希)

  validate_camel_case_read_preference_mode(read_pref[:mode] || read_pref['mode'])
end

validate_camel_case_read_preference_mode (模式) ⇒对象

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

引发:



43
44
45
46
47
48
49
50
# File 'lib/ Mongo/lint.rb', 第 43 行

def validate_camel_case_read_preference_mode(模式)
  return 除非 已启用?

  return 除非 模式
  return if %w[主节点 primaryPreferred 从节点 secondaryPreferred nearest].包括?(模式.to_s)

  提高 错误::LintError, "无效的读取偏好(read preference)模式: #{ 模式 } "
end

validate_read_concern_option (read_concern) ⇒对象

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

Validates the provided hash as a read concern 对象, per the 读关注(read concern)/写关注(write concern) specification (https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.md#读关注(read concern))。

为方便起见,此方法还接受 nil 作为输入。

发送到服务器的读关注(read concern)文档可能包含其他字段,示例afterClusterTime。这些字段由驱动程序内部生成,用户无法指定(如果由用户指定,则可能会导致不正确的行为),因此此方法会禁止这些字段。

参数:

  • read_concern (哈希)

    读关注(read concern)选项哈希,具有以下可选键:

    • :level -- 以符号表示的读取偏好(read preference)级别;有效值为::local:大多数:快照

引发:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ Mongo/lint.rb', 第 71 行

def validate_read_concern_option(read_concern)
  return 除非 已启用?
  return if read_concern.nil?
  提高 错误::LintError, "读关注不是哈希: #{ read_concern } " 除非 read_concern.is_a?(哈希)
  return if read_concern.空?

  密钥 = read_concern.密钥
  allowed_keys = if read_concern.is_a?(BSON::文档)
                   # 允许无关访问
                   [ 'level' ]
                 else
                   # 不允许无关紧要的访问权限
                   [ :level ]
                 end
  提高 错误::LintError, "读关注的键无效: #{ keys .inspect } } " if 密钥 != allowed_keys

  等级 = read_concern[:level]
  return if %i[local available majority linearizable snapshot].包括?(等级)

  提高 错误::LintError, "读关注级别无效:值必须是符号: #{ level .inspect } } "
end

validate_underscore_read_preference (read_pref) ⇒对象

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

引发:



15
16
17
18
19
20
21
# File 'lib/ Mongo/lint.rb', 第 15 行

def validate_underscore_read_preference(read_pref)
  return 除非 已启用?
  return if read_pref.nil?
  提高 错误::LintError, "读取偏好不是哈希值: #{ read_pref } " 除非 read_pref.is_a?(哈希)

  validate_underscore_read_preference_mode(read_pref[:mode] || read_pref['mode'])
end

.validate_underscore_read_preference_mode(mode) ⇒ Object

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

引发:



24
25
26
27
28
29
30
31
# File 'lib/ Mongo/lint.rb', 第 24 行

def validate_underscore_read_preference_mode(模式)
  return 除非 已启用?

  return 除非 模式
  return if %w[主节点 primary_preferred 从节点 secondary_preferred nearest].包括?(模式.to_s)

  提高 错误::LintError, "无效的读取偏好(read preference)模式: #{ 模式 } "
end