class ActiveRecordPartitioning::ConnectionPools

Attributes

key_name[R]
store[R]

Public Class Methods

new(key_name, store={}) click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 10
def initialize(key_name, store={})
  @key_name = key_name
  @store = store
end

Public Instance Methods

[](klass_name) click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 21
def [](klass_name)
  config = ActiveRecordPartitioning.current_connection_pool_config
  if config.nil?
    raise NoActiveConnectionPoolError.new("#{size} connection pools in cache, keys: #{keys.inspect}, pool configs: #{values.map(&:spec).map(&:config).inspect}") if size > 1
    values.first
  else
    @store[connection_pool_key(config)]
  end
end
[]=(klass_name, pool) click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 31
def []=(klass_name, pool)
  @store[connection_pool_key(pool.spec.config)] = pool
end
delete_if(&block) click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 35
def delete_if(&block)
  @store.delete_if(&block)
end
each(&block) click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 43
def each(&block)
  @store.each(&block)
end
each_value(&block) click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 39
def each_value(&block)
  @store.each_value(&block)
end
keys() click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 51
def keys
  @store.keys
end
merge!(pools) click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 15
def merge!(pools)
  pools.each do |klass_name, pool|
    self[klass_name] = pool
  end
end
size() click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 55
def size
  @store.size
end
values() click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 47
def values
  @store.values
end

Private Instance Methods

connection_pool_key(config) click to toggle source
# File lib/activerecord_partitioning/connection_pools.rb, line 60
def connection_pool_key(config)
  config[@key_name]
end