Class: ActiveRecord::ConnectionAdapters::ConnectionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/codefly.rb

Instance Method Summary collapse

Instance Method Details

#retrieve_connection(klass) ⇒ Object

:nodoc:

Raises:

  • (ConnectionNotEstablished)


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

def retrieve_connection(klass) #:nodoc:
  pool = retrieve_connection_pool(klass)
  raise ConnectionNotEstablished, "No connection pool for #{klass}" unless pool
  conn = if Thread.current[:connection].blank?
    pool.connection
  else
    if Thread.current[:connection] == :new
      ActiveRecord::Base.connection_pool.checkout()
    else
      Thread.current[:connection]
    end
  end
  raise ConnectionNotEstablished, "No connection for #{klass} in connection pool" unless conn
  conn
end