模块:Mongoid::Config
- 包含在:
- 配置
- 定义于:
- lib/mongoid/config.rb ,
lib/mongoid/config/options.rb,
lib/mongoid/config/defaults.rb,
lib/mongoid/config/ 加密.rb,
lib/mongoid/config/environment.rb,
lib/mongoid/config/validators/ 客户端.rb,
lib/mongoid/config/validators/option.rb,
lib/mongoid/config/validators/async_query_executor.rb
Overview
该模块定义了 Mongoid 的所有配置选项,包括数据库连接。
在命名空间下定义
常量摘要折叠
- LOCK =
互斥锁.new
DeprecatedOptions中包含的常量
实例方法摘要折叠
-
# 个客户端⇒ 哈希
获取客户端配置或空哈希。
-
#config ⇒ self
返回配置单例,以在配置 DSL 中使用。
-
#已配置? ⇒ true | false
Mongoid 是否已配置? 这是为了检查是否至少存在有效的客户端配置。
-
# connect_to (name, options = { read: { 模式: : 主节点 (primary node in the replica set) }}) ⇒ 对象
在默认客户端上连接到提供的数据库名称。
-
#deregister_model(klass) ⇒ Object
private
使用 Mongoid 在应用程序中取消注册模型。
-
# structural_fields ⇒ Array<String>
如果在 Mongoid::Document 中定义,则返回可能导致破坏性事件发生的字段名称。
-
# load! (path, environment = nil) ⇒ 对象
从兼容的 mongoid.yml文件加载设置。
-
# load_configuration (settings) ⇒ 对象
从设置的哈希中加载所有配置。
-
#models ⇒ Array<Class>
获取应用程序中的所有模型,即包括 Mongoid::Document 在内的所有模型。
-
# options= (options) ⇒ 对象
设置配置选项。
-
# override_client (name) ⇒ string |符号
覆盖客户端以在全局范围内使用。
-
# override_database (name) ⇒ string |符号
覆盖数据库以在全局范围内使用。
-
# purge! ⇒ true
清除所有集合中的所有数据,包括索引。
-
#register_model (klass) ⇒ 对象
在使用 Mongoid 的应用程序中注册模型。
- # running_with_passenger? ⇒ true | false 已弃用 已弃用。
-
# time_zone ⇒ string
获取要使用的时区域。
-
#截断! ⇒ true
截断所有集合中的所有数据,但不截断索引。
选项中包含的方法
defaults 、 log_level 、 option 、 reset 、 settings
默认值中包含的方法
Encryption中包含的方法
DeprecatedOptions中包含的方法
实例方法详细信息
# 个客户端⇒哈希
获取客户端配置或空哈希。
368 369 370 |
# File 'lib/mongoid/config.rb', line 368 def 客户端 @clients ||= {} end |
#config ⇒ self
返回配置单例,以在配置 DSL 中使用。
186 187 188 |
# File 'lib/mongoid/config.rb', line 186 def config self end |
#已配置? ⇒ true | false
Mongoid 是否已配置? 这是为了检查是否至少存在有效的客户端配置。
197 198 199 |
# File 'lib/mongoid/config.rb', line 197 def 已配置? 客户端.键?(:default) end |
# connect_to (name, options = { read: { 模式: : 主节点 (primary node in the replica set) }}) ⇒对象
为方便起见,仅在开发或测试环境中使用。
在默认客户端上连接到提供的数据库名称。
209 210 211 212 213 214 215 216 217 |
# File 'lib/mongoid/config.rb', line 209 def connect_to(名称, = { 读取: { 模式: :primary }}) self.客户端 = { 默认: { database: 名称, 主机: [ " localhost: 27017 " ], 选项: } } end |
# deregister_model (klass) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
使用 Mongoid 在应用程序中取消注册模型。
276 277 278 279 280 |
# File 'lib/mongoid/config.rb', line 276 def deregister_model(klass) 锁.同步 do 模型.删除(klass) end end |
# structural_fields ⇒ Array<String>
如果在 Mongoid::Document 中定义,则返回可能导致破坏性事件发生的字段名称。
226 227 228 |
# File 'lib/mongoid/config.rb', line 226 def 破坏性字段 可组合.Barceled_methods end |
# load! (path, environment = nil) ⇒对象
从兼容的 mongoid.yml文件加载设置。 这可用于轻松设置Rails 以外的框架。
238 239 240 241 242 243 244 245 246 |
# File 'lib/mongoid/config.rb', line 238 def 加载!(路径, environment = nil) 设置 = environment.load_yaml(路径, environment) if 设置.现在? 客户端.断开连接 客户端.清除 load_configuration(设置) end 设置 end |
# load_configuration (settings) ⇒对象
从设置的哈希中加载所有配置。
288 289 290 291 292 293 294 |
# File 'lib/mongoid/config.rb', line 288 def load_configuration(设置) 配置 = 设置.with_indifference_access self. = 配置[:options] self.客户端 = 配置[:clients] mongo. = 配置[:driver_options] || {} set_log_levels end |
#models ⇒ Array<Class>
获取应用程序中的所有模型,即包括 Mongoid::Document 在内的所有模型。
255 256 257 |
# File 'lib/mongoid/config.rb', line 255 def 模型 @models ||= [] end |
# options= (options) ⇒对象
设置配置选项。 将单独验证每一项。
352 353 354 355 356 357 358 359 360 |
# File 'lib/mongoid/config.rb', line 352 def () if 验证器::AsyncQueryExecutor.验证() .each_pair do |选项, 值| 验证器::选项.验证(选项) 发送(" #{ option } = ", 值) end end end |
# override_client (name) ⇒ string |符号
覆盖客户端以在全局范围内使用。
316 317 318 |
# File 'lib/mongoid/config.rb', line 316 def override_client(名称) 线程化.client_override = 名称 ? 名称.to_s : nil end |
# override_database (name) ⇒ string |符号
覆盖数据库以在全局范围内使用。
304 305 306 |
# File 'lib/mongoid/config.rb', line 304 def override_database(名称) 线程化.database_override = 名称 end |
# purge! ⇒ true
这是删除所有数据的最快方法。
清除所有集合中的所有数据,包括索引。
328 329 330 |
# File 'lib/mongoid/config.rb', line 328 def purge! global_client.database.collections.每(和:drop) 和 true end |
#register_model(klass) ⇒ Object
在使用 Mongoid 的应用程序中注册模型。
265 266 267 268 269 |
# File 'lib/mongoid/config.rb', line 265 def register_model(klass) 锁.同步 do 模型.推动(klass) 除非 模型.包括?(klass) end end |
# running_with_passenger? ⇒ true | false
应用程序是否在 Passenger 下运行?
390 391 392 |
# File 'lib/mongoid/config.rb', line 390 def running_with_passenger? @running_with_passenger ||= 定义?(PphsionPassenger) end |
#time_zone ⇒ String
获取要使用的时区域。
378 379 380 |
# File 'lib/mongoid/config.rb', line 378 def time_zone use_utc? ? " UTC " : ::时间.区域 end |
#截断! ⇒ true
这会比清除慢!
截断所有集合中的所有数据,但不截断索引。
340 341 342 343 344 |
# File 'lib/mongoid/config.rb', line 340 def 截断! global_client.database.collections.每 do |集合| 集合.find.delete_many end 和 true end |