Processing rc file - critical comment asked

R

Ronald Fischer

I have already a solution for my problem, but I would be glad if some
kind=20
soul could have a look on it and give suggestion for improvement...

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

# Example rc file
TIMEOUT=3D130
LOGFILE=3DENV[HOME]+"/tmp/appl.log"

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=20
application I can accept it - security is not a big issue in this=20
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"+File.read(rcfile)+"\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?

Ronald
--=20
Ronald Fischer <[email protected]>
Phone: +49-89-452133-162
=20
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,310
Members
47,977
Latest member
MillaDowdy

Latest Threads

Top