模块:Mongoid::Clients
- 扩展方式:
- ActiveSupport::Concern
- 包括:
- 选项,会话, StorageOptions
- 包含在:
- 可组合
- 定义于:
- lib/mongoid/clients.rb ,
lib/mongoid/clients/factory.rb,
lib/mongoid/clients/options.rb,
lib/mongoid/clients/sessions.rb,
lib/mongoid/clients/storage_options.rb,
lib/mongoid/clients/validators/ 存储.rb
Overview
Mongoid::Document 中包含的 Mixin 模块增加了数据库客户端连接功能。 还包含与管理数据库客户端相关的单例类方法。
在命名空间下定义
模块: Factory 、 Options 、 Sessions 、 StorageOptions 、 Validators
实例属性摘要
StorageOptions 中包含的属性
类方法摘要折叠
-
。 clear ⇒ 数组
清除当前线程中的所有客户端。
-
。 clients ⇒ Hash<Symbol, Mongo::Client>
返回按名称索引的存储客户端。
-
.default ⇒ Mongo::Client
获取默认客户端。
-
。断开连接⇒ true
断开所有活动客户端的连接。
-
。 reconnect ⇒ true
重新连接所有活动客户端。
-
。 设立 (name, 客户端) ⇒ Mongo::Client
使用提供的名称存储客户端。
-
。 with_name (name) ⇒ Mongo::Client
获取具有提供名称的存储客户端。
会话中包含的方法
选项中包含的方法
# 集合 , #collection_name , #mongo_client , #persistence_context , #persistence_context? , #with
StorageOptions 中包含的方法
#remember_storage_options! , #storage_options
类方法详细信息
。 clear ⇒数组
清除当前线程中的所有客户端。
29 30 31 |
# File 'lib/mongoid/clients.rb', line 29 def 清除 客户端.清除 end |
。 clients ⇒ Hash<Symbol, Mongo::Client>
返回按名称索引的存储客户端。
102 103 104 |
# File 'lib/mongoid/clients.rb', line 102 def 客户端 @clients ||= {} end |
.default ⇒ Mongo::Client
获取默认客户端。
39 40 41 |
# File 'lib/mongoid/clients.rb', line 39 def 访问 with_name(:default) end |
。断开连接⇒ true
断开所有活动客户端的连接。
49 50 51 52 |
# File 'lib/mongoid/clients.rb', line 49 def 断开连接 客户端.each_value(和:close) true end |
。 reconnect ⇒ true
重新连接所有活动客户端。
60 61 62 63 |
# File 'lib/mongoid/clients.rb', line 60 def 重新连接 客户端.each_value(和:reconnect) true end |
。 设立 (name, 客户端) ⇒ Mongo::Client
使用提供的名称存储客户端。
95 96 97 |
# File 'lib/mongoid/clients.rb', line 95 def 集(名称, 客户端) 客户端[名称.to_sym] = 客户端 end |
。 with_name (name) ⇒ Mongo::Client
获取具有提供名称的存储客户端。 如果不存在具有给定名称的客户端,则会创建、存储并返回一个新客户端。
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mongoid/clients.rb', line 75 def with_name(名称) name_as_symbol = 名称.to_sym return 客户端[name_as_symbol] if 客户端[name_as_symbol] CREATE_LOCK.同步 do if (key_vault_client = Mongoid.客户端.dig(name_as_symbol, :options, :auto_encryption_options, :key_vault_client)) 客户端[key_vault_client.to_sym] ||= 客户端::工厂.创建(key_vault_client) end 客户端[name_as_symbol] ||= 客户端::工厂.创建(名称) end end |