JRuby - keeping your database.yml really DRY
Contents
I am experimenting in JRuby and use database in virtual machine (VMWare Fusion). This is great because you can have multiple versions of multiple databases ready without polluting the notebook. One downsize though is that IP address of the database will change between the VM restarts.
First important setting in Fusion is to use the 'NAT' option rather than 'Bridged'. With NAT, you database host IP address will not follow the network. It was quite annoying to change it from 192.168.X to 192.168.Y everytime I reconnected at home from work or vice versa.
But even with this setting, the IP may change as you restart the VM and you will have to modify the database.yml. To keep the amount of editing minimal, here is my database.yml for the shoplet example:
[code language='ruby']
common: &common
adapter: jdbc
driver: com.mysql.jdbc.Driver
password: shoplet
development:
<< : *common
url: /shoplet_dev
username: shoplet_dev
test:
<< : *common
url: /shoplet_test
username: shoplet_test
production:
<< : *common
url: /shoplet_prod
username: shoplet_prod
[/code]
It will work in Ruby as well of course - with different (non-jdbc based) adapter..
Author Miro Adamy
LastMod 2008-01-03
License (c) 2006-2020 Miro Adamy