Class: ActiveRecordUtils::Browser
- Inherits:
-
Object
- Object
- ActiveRecordUtils::Browser
- Defined in:
- lib/activerecord/utils/browser.rb
Overview
also (formerly) known as connection manager
Defined Under Namespace
Classes: AbstractModel, Column, Connection, Result, Table
Constant Summary collapse
- CONNECTS =
get connection names
def connection_names ActiveRecord::Base.configurations.keys end {}
Instance Method Summary collapse
-
#connection_for(key) ⇒ Object
cache connections.
Instance Method Details
#connection_for(key) ⇒ Object
cache connections
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/activerecord/utils/browser.rb', line 18 def connection_for( key ) # cache connections - needed? why? why not?? # hack: for now only use cached connection if still active # if not; get a new one to avoid connection closed errors in rails con = CONNECTS[ key ] if con puts "[Browser] cached connection found; con.active? #{con.active?}" unless con.active? puts "[Browser] *** reset cached connection (reason: connection stale/closed/not active)" con = CONNECTS[ key ] = nil end end if con.nil? con = CONNECTS[ key ] = AbstractModel.connection_for( key ) end # note: make sure connection is active? # use verify! - will try active? followed by reconnect! # - todo: check ourselves if active? - why? why not?? # -- not working w/ rails - after verify! still getting error w/ closed connection # -- con.verify! # wrap ActiveRecord connection in our own connection class Connection.new( con, key ) end |