模块:Mongo::Options::Mapper
Overview
用于各种选项映射行为的实用程序类。
实例方法摘要折叠
-
#transform (options, mappings) ⇒ 哈希
在给定映射的情况下,将提供的选项转换为一设立新选项。
-
#transform_documents (options, mappings, 文档 = BSON::Document.new) ⇒ BSON::Document
在给定映射的情况下,将提供的选项转换为一设立新选项。
-
#transform_keys_to_strings (options) ⇒ 哈希
将选项的所有键转换为字符串。
-
#transform_keys_to_symbols (options) ⇒ 哈希
将选项的所有键转换为符号。
-
#transform_values_to_strings (options) ⇒ 哈希
将所有符号值转换为字符串。
实例方法详细信息
#transform (options, mappings) ⇒哈希
在给定映射的情况下,将提供的选项转换为一设立新选项。
不存在于所提供映射中的选项将按原样返回。
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ Mongo/options/mapper.rb', line 40 def 转换(Transform)(, mappings) map = transform_keys_to_strings(mappings) opts = transform_keys_to_strings() opts.each_with_object({}) do |(key, 值), 已转换| if map[key] 已转换[map[key]] = 值 else 已转换[key] = 值 end end end |
#transform_documents (options, mappings, 文档 = BSON::Document.new) ⇒ BSON::Document
在给定映射的情况下,将提供的选项转换为一设立新选项。 输入和输出均应为BSON::Documents,因此无需进行显式string转换。
66 67 68 69 70 71 |
# File 'lib/ Mongo/options/mapper.rb', line 66 def transform_documents(, mappings, 文档 = BSON::文档.new) .each_with_object(文档) do |(key, 值), 已转换| 名称 = mappings[key] 已转换[名称] = 值 if 名称 && !值.nil? end end |
#transform_keys_to_strings (options) ⇒哈希
将选项的所有键转换为字符串。
83 84 85 86 87 |
# File 'lib/ Mongo/options/mapper.rb', line 83 def transform_keys_to_strings() .each_with_object({}) do |(key, 值), 已转换| 已转换[key.to_s] = 值 end end |
#transform_keys_to_symbols (options) ⇒哈希
将选项的所有键转换为符号。
99 100 101 102 103 |
# File 'lib/ Mongo/options/mapper.rb', line 99 def transform_keys_to_symbols() .each_with_object({}) do |(key, 值), 已转换| 已转换[key.to_sym] = 值 end end |
#transform_values_to_strings (options) ⇒哈希
将所有符号值转换为字符串。
115 116 117 118 119 |
# File 'lib/ Mongo/options/mapper.rb', line 115 def transform_values_to_strings() .each_with_object({}) do |(key, 值), 已转换| 已转换[key] = 值.is_a?(符号) ? 值.to_s : 值 end end |