# Processing rc file - critical comment asked

**URL:** <https://www.ruby-forum.com/t/processing-rc-file-critical-comment-asked/108029>\
**Category:** Ruby\
**Created:** [June 28, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/processing-rc-file-critical-comment-asked/108029 "2007-06-28T15:17:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [June 28, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/processing-rc-file-critical-comment-asked/108029/1 "2007-06-28T15:17:28Z")

</div>

I have already a solution for my problem, but I would be glad if some  
kind  
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=130  
LOGFILE=ENV[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  
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”+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
