From: Phrogz Date: 2007-02-09T01:35:08+09:00 Subject: Re: Ruby as a configuration language Tapio Kelloniemi wrote: > I wish I could write the profiles in Ruby to avoid > creating yet another advanced configuration language. Some people will suggest YAML. That's certainly a reasonable way to go. Don't create your own config language when a simple markup exists that translates painlessly into Ruby data structures. > # An example package description file. The actual building commands are > # written in a bash script. > name = "gcc" > version = "4.1.1" > title = " "GNU Compiler Collection" > description = "..." > > archive { > localname = "#{name}-#{version}.tar.bz2" > originalname = "#{name}-#{version}.tar.gz" > baseurl "ftp://ftp.gnu.org/gnu/gcc/#{version}/" > baseurl "ftp.mirror.site/gnu/gcc/#{version}/" > convert = "gz-bz2" > } > > # Optional components > feature "gfortran" { > title = "Fortran compiler" > depend "gmp" > } > > ### END example If you want a true DSL, here's some untested code pointing you in the right direction. I have no idea if you can have more than one archive, or more than one feature, or more than one baseurl per Archive...but you can do it. class Archive attr_accessor :localname, :originalname, :baseurl, :convert end class Feature attr_accessor :title, :dependency def depend( depends_on ) @dependency = depends_on end end def archive( &block ) $archive = Archive.new $archive.instance_eval( &block ) end $features = [] def feature( &block ) f = Feature.new $features << f f.instance_eval( &block ) end