From: "Ara.T.Howard" Date: 2005-08-19T08:53:37+09:00 Subject: Re: domain-specific language On Fri, 19 Aug 2005, Joe Van Dyk wrote: > I'm writing an application that controls a group/cluster of linux > computers/nodes. I need to have a configuration file that lists the > nodes in the cluster. > > It would be neat if the configuration file was in Ruby. If I had > nodes named node1 and node3, the configuration file could look a > little like: > > node :node1 do > ip 192.whatever > title "Node 1" > end > > node :node2 do > ip 192.whatever > title "Node 2" > end > > So, is there some standard Ruby idiom for how to read a file and > execute the code? Just load the file and instance_eval it? harp:~ > cat a.rb config = <<-config nodes : 1 : ip : 192.whatever title : node 1 2 : ip : 192.whatever title : node 2 config require 'yaml' config = YAML::load config config['nodes'].each do |nid, node| puts "node <#{ nid }> => <#{ node.inspect }>" end harp:~ > ruby a.rb node <1> => <{"title"=>"node 1", "ip"=>"192.whatever"}> node <2> => <{"title"=>"node 2", "ip"=>"192.whatever"}> so all you have to do is 'YAML::load(IO::read(configfile))'. what kind of clustering are you working with? you may, or may not, find this useful: http://raa.ruby-lang.org/project/rq/ http://www.linuxjournal.com/article/7922 cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================