Class: ActiveRecord::ConnectionAdapters::PoolManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializePoolManager

Returns a new instance of PoolManager.



6
7
8
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb', line 6

def initialize
  @name_to_role_mapping = Hash.new { |h, k| h[k] = {} }
end

Instance Method Details

#get_pool_config(role, shard) ⇒ Object



34
35
36
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb', line 34

def get_pool_config(role, shard)
  @name_to_role_mapping[role][shard]
end

#pool_configs(role = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb', line 18

def pool_configs(role = nil)
  if role
    @name_to_role_mapping[role].values
  else
    @name_to_role_mapping.flat_map { |_, shard_map| shard_map.values }
  end
end

#remove_pool_config(role, shard) ⇒ Object



30
31
32
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb', line 30

def remove_pool_config(role, shard)
  @name_to_role_mapping[role].delete(shard)
end

#remove_role(role) ⇒ Object



26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb', line 26

def remove_role(role)
  @name_to_role_mapping.delete(role)
end

#role_namesObject



14
15
16
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb', line 14

def role_names
  @name_to_role_mapping.keys
end

#set_pool_config(role, shard, pool_config) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb', line 38

def set_pool_config(role, shard, pool_config)
  if pool_config
    @name_to_role_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_namesObject



10
11
12
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/pool_manager.rb', line 10

def shard_names
  @name_to_role_mapping.values.flat_map { |shard_map| shard_map.keys }
end