Forum: Ruby Processing rc file - critical comment asked

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C667185722eaecf12461cb423dc8b410?d=identicon&s=25 Ronald Fischer (Guest)
on 2007-06-28 15:17
(Received via mailing list)
I have already a solution for my problem, but I would be glad if some
soul could have a look on it and give suggestion for improvement...

Problem: My application can be controled by a kind of "rc file",
various options. The options are defined using the Ruby syntax for
constants. For example:

  # Example rc file

There are many possible options, but of course not all of them need to
be specified.

My solution is basically to evaluate the option file and access the
constants. I am aware that this imposes a pretty high security risk,
since *any* Ruby code could be put into the rc file, but for my
application I can accept it - security is not a big issue in this
particular case.

An option is "set" by calling a certain function in my application.

Here is my code:

# Evaluate RC file in the context of a module. The name of the
# rc file is on variable rcfile.
eval("module Rc\n""\nend")

# Now set the options according to the RC file
Scheduler.setTimeout(Rc::TIMEOUT) if Rc.const_defined?('TIMEOUT');
Logger.setLogFile(Rc::LOGFILE) if Rc.const_defined?('LOGFILE');
... and so on

This works fine, but I don't like it much. It is a lot of typing for
each option, and it is easy to make a typing error:

# Ooops, typo (REMOTEHOST vs. REMOTE_HOST)
SshConnect.setHost(Rc::REMOTEHOST) if Rc.const_defined?('REMOTE_HOST')

Any idea of how I could do it better?

This topic is locked and can not be replied to.