Class: SlavePools::Pools

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Enumerable
Defined in:
lib/slave_pools/pools.rb

Instance Method Summary collapse

Constructor Details

#initializePools

Returns a new instance of Pools.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/slave_pools/pools.rb', line 7

def initialize
  pools = {}
  pool_configurations.group_by{|_, name, _| name }.each do |name, set|
    pools[name.to_sym] = SlavePools::Pool.new(
      name,
      set.map{ |conn_name, _, replica_name|
        connection_class(name, replica_name, conn_name)
      }
    )
  end

  if pools.empty?
    SlavePools.log :info, "No pools found for #{SlavePools.config.environment}. Loading a default pool with master instead."
    pools[:default] = SlavePools::Pool.new('default', [ActiveRecord::Base])
  end

  super pools
end