class MultiConnection::ConnectionAdapters::ConnectionHandler

Attributes

spec[RW]

Public Class Methods

new() click to toggle source
# File lib/multi_connection.rb, line 60
def initialize
  @spec_to_pool = ThreadSafe::Cache.new(:initial_capacity => 2)
end

Public Instance Methods

connection_pool_list() click to toggle source
# File lib/multi_connection.rb, line 64
def connection_pool_list
  @spec_to_pool.values.compact
end
establish_connection(owner, spec) click to toggle source
# File lib/multi_connection.rb, line 68
def establish_connection(owner, spec)
  @spec_to_pool[self.spec] =
    ::ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec)
end
remove_connection(spec) click to toggle source
# File lib/multi_connection.rb, line 73
def remove_connection(spec)
  if pool = @spec_to_pool[spec]
    pool.automatic_reconnect = false
    pool.disconnect!
    pool.spec.config
  end
end
retrieve_connection_pool(klass=nil) click to toggle source
# File lib/multi_connection.rb, line 81
def retrieve_connection_pool(klass=nil)
  # Base.establish_connection will resolve the spec for us
  # and call our #establish_connection method
  @spec_to_pool[spec] || ::ActiveRecord::Base.establish_connection(spec)
end