Class: ActiveRecord::ConnectionAdapters::PoolManager
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activerecord/lib/active_record/connection_adapters/pool_manager.rb |
Class Method Summary
- .new ⇒ PoolManager constructor
Instance Method Summary
Constructor Details
.new ⇒ PoolManager
# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 6
def initialize @role_to_shard_mapping = Hash.new { |h, k| h[k] = {} } end
Instance Method Details
#each_pool_config(role = nil, &block)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 26
def each_pool_config(role = nil, &block) if role @role_to_shard_mapping[role].each_value(&block) else @role_to_shard_mapping.each_value do |shard_map| shard_map.each_value(&block) end end end
#get_pool_config(role, shard)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 44
def get_pool_config(role, shard) @role_to_shard_mapping[role][shard] end
#pool_configs(role = nil)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 18
def pool_configs(role = nil) if role @role_to_shard_mapping[role].values else @role_to_shard_mapping.flat_map { |_, shard_map| shard_map.values } end end
#remove_pool_config(role, shard)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 40
def remove_pool_config(role, shard) @role_to_shard_mapping[role].delete(shard) end
#remove_role(role)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 36
def remove_role(role) @role_to_shard_mapping.delete(role) end
#role_names
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 14
def role_names @role_to_shard_mapping.keys end
#set_pool_config(role, shard, pool_config)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 48
def set_pool_config(role, shard, pool_config) if pool_config @role_to_shard_mapping[role][shard] = pool_config else raise ArgumentError, "The `pool_config` for the :#{role} role and :#{shard} shard was `nil`. Please check your configuration. If you want your writing role to be something other than `:writing` set `config.active_record.writing_role` in your application configuration. The same setting should be applied for the `reading_role` if applicable." end end
#shard_names
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/pool_manager.rb', line 10
def shard_names @role_to_shard_mapping.values.flat_map { |shard_map| shard_map.keys }.uniq end