Ruby equivalent for property or config.xml?

Hi,

i have a ruby script that should be controlled via
configfile, similar as a propertyfile or config.xml in java.

What’s the ruby equivalent for that ?

Gilbert

On 23/02/07, Rebhan, Gilbert [email protected] wrote:

Your best bet is probably YAML which is part of the standard library.

Farrel

Farrel L. wrote:

Your best bet is probably YAML which is part of the standard library.

Farrel

Or just a ruby file…

module Config
DATABASE = {:adapter => ‘foo’ …}
FROBNICATOR = :fozzbangle
LOCATION = :coozbain
end

On 2/23/07, Rebhan, Gilbert [email protected] wrote:

i have a ruby script that should be controlled via
configfile, similar as a propertyfile or config.xml in java.

What’s the ruby equivalent for that ?

YAML is what you want, though parsing properties files into ruby
hashes is straightforward.

Even in java, XML files for configuration are overkill.

YAML is what you want, though parsing properties files into ruby
hashes is straightforward.

I wondered whether some features of Apache Jakarta Commons Configuration
format are available with YAML (or another Ruby gismo):

http://jakarta.apache.org/commons/configuration/apidocs/org/apache/commons/configuration/PropertiesConfiguration.html

Two interesting features:

  1. Variable expansion:

user.name = miles
first_file = /home/${user.name}/first
app_title = ${user.name}'s homepage

I think variable expansion is done on reference (“lazy”). YAML has
aliases, but can’t concatenate strings (which is OK, because YAML is for
object (de)serialization…).

  1. Layout preservation: The ‘load’ methods saves the layout of the
    properties file, including comments, line order, indentation. The ‘save’
    method tries to preserve as much of it as possible. See:

http://jakarta.apache.org/commons/configuration/apidocs/org/apache/commons/configuration/PropertiesConfigurationLayout.html

Best,
Dov.