title: Connecting to unknown number of databases using ActiveRecord
body: <p>I am writing a ruby script that needs to connect to a primary database in order to retrieve a list of secondary databases to connect to. The steps I need to carry out are:</p>
  
  <ol>
  <li>Connect to primary DB</li>
  <li>Retrieve list of secondary databases to connect to</li>
  <li>Iterate through list of secondary databases, extracting a single model from each database</li>
  </ol>
  
  <p>I don't need to be connected to multiple secondary databases at once, so open -> retrieve object -> close is fine.</p>
  
  <p>All of the examples I have seen so far describe multiple connections where the databases are described in database.yml, which is not possible here as the number of databases I need to connect to can vary.</p>
  
  <p>This <a href="http://tenderlovemaking.com/2011/10/20/connection-management-in-activerecord.html" rel="nofollow">blog post</a> describes using a connection pool as follows:</p>
  
  <pre><code>spec = database_a
  ActiveRecord::ConnectionPool.open(spec) do |conn|
    User.find_all
  end
  
  spec = database_b
  ActiveRecord::ConnectionPool.open(spec) do |conn|
    User.find_all
  end
  </code></pre>
  
  <p>However, <code>ConnectionPool</code> seems to have changed and the <code>.open</code> method no longer exists.</p>
  
  <p>I would appreciate any pointers.</p>