class Scheduler::Connection
Public Class Methods
current_db()
click to toggle source
# File lib/scheduler/connection.rb, line 4 def current_db ActiveRecord::Base.connection_pool.spec.config[:db_key] || "default" end
current_hostname()
click to toggle source
# File lib/scheduler/connection.rb, line 8 def current_hostname config = ActiveRecord::Base.connection_pool.spec.config config[:host_names].nil? ? config[:host] : config[:host_names].first end
establish_connection(db)
click to toggle source
# File lib/scheduler/connection.rb, line 13 def establish_connection(db) config = ActiveRecord::Base.configurations[db] ActiveRecord::Base.establish_connection(config) end
with_connection(db) { |db| ... }
click to toggle source
# File lib/scheduler/connection.rb, line 18 def with_connection(db) old = current_db connected = ActiveRecord::Base.connection_pool.connected? establish_connection(:db => db) unless connected && db == old rval = yield db unless connected && db == old ActiveRecord::Base.connection_handler.clear_active_connections! establish_connection(:db => old) ActiveRecord::Base.connection_handler.clear_active_connections! unless connected end rval end