Ruby in the config file

Hello all,
I am trying to make my Ruby project portable between Windows and Linux.
In my config file, I’m having to specify a socket for MySql on Linux.
However, the socket file doesn’t exist under Windows. In fact, it only
seems to work when the socket key is totally taken out under Windows.

So, what I’d like to do is put some sort of conditional logic in the
YAML file. I was thinking that I could check to see if the socket file
exists and output the key if it does, otherwise I’d output blank. Any
ideas?

Thanks,
Will


Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low
rates.

On Oct 23, 2006, at 5:14 PM, Will G. wrote:

output blank. Any ideas?

Thanks,
Will

Since the database.yml file is processed by eRB, here’s what I do to
keep connection and password information specific to the machine:

==== config/database.yml ====

vvv Copy the following two YAML maps to a file called config/

mydatabase.yml

login: &login
username: sample
password: sample

connection: &connection
host: 127.0.0.1
port: 3306

^^^ Copy the previous two YAML maps to a file called config/

mydatabase.yml

<%= file = File.join(RAILS_ROOT, “config”, “mydatabase.yml”)
IO.read(file) if File.exist?(file) %>

development:
adapter: mysql
database: top_development
<<: *login
<<: *connection

same for test and production

#END

==== config/mydatabase.yml ====

“rob-biedenharns-computer.local”

login: &login

username: sample

password: sample

connection: &connection
host: localhost
socket: /tmp/mysql.sock

#END

Note that the YAML maps stay in config/database.yml as the defaults.
If the file config/mydatabase.yml exists, it can redefine either or
both the ‘login’ or ‘connection’ maps. In this case, my own local
one uses the same default username and password for the login, so
it’s not redefined. The connection, however, is via a socket on my
Mac and there are similar config/mydatabase.yml files on the other
development machines and on the staging and production servers.

The config/database.yml file is kept in version control, but the
config/mydatabase.yml file is NOT. I have manual backup copies of a
TxD-mydatabase.yml and so on for other machines, but the local login
and connection information stays only on the machine it is set for.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]