Help please - Trying to connect to a user defined database

Hi,

I’m stuck on the following problem. Using a legacy system, we have
multiple databases to need to connect to. I solved this problem using
the use_db plugin, as most of the information is just in two databases.

However, I now need to connect to a number of databases, called by the
user.

I could do this by hard coding each and every database into
database.yml, but this would seriously defeat DRY principles, as for
these databases they are all hosted on the same host and port. I also
want them all to be using a foo connection

Example

foo_development
adapter: some_adapter
database: wibble
username: read_only
password: xxxxx
host: this_one
port: 3333

foo_development
adapter: some_adapter
database: snark
username: read_only
password: xxxxx
host: this_one
port: 3333

foo_development
adapter: some_adapter
database: boom
username: read_only
password: xxxxx
host: this_one
port: 3333

I am rather stuck on trying to use ERb to only use a user defined
database name, both attempting a global variable, and method defined in
the base class model.

Any help here would be much appreciated.

Cheers

Andy