class ActiveRecordUtils::Browser

simple (generic) database browser - no models required

Constants

CONNECTS

get connection names

def connection_names
  ActiveRecord::Base.configurations.keys
end

Public Instance Methods

connection_for( key ) click to toggle source
# 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