0

In order to have only a single point of configuration for my app I need to make a YAML config file that is also valid ruby code. I.e. a mixed syntax file that can be parsed as YAML and parsed as ruby.

My application is a suite of processes managed by the god gem. I want to load a new group of maintained processes (watches) for each new configuration file.

God allows loading a new app.god (ruby) file with new watches defined, but I don't want an app.god and app.yml, just one file. Simplest might be to just have the app.god file and include the configuration within that, but I preferred the idea of a yml file that was also valid ruby code.

dreftymac
  • 31,404
  • 26
  • 119
  • 182
meesern
  • 2,518
  • 27
  • 29

1 Answers1

0
#I found this that might be helpful:
#This is a valid ruby and a valid YAML file
#Comments are the same in YAML and ruby

true ?true: 
- <<YAML.to_i
# At this point in ruby it is the contents of a here doc (that will be 
# converted to an integer and negated if true happens not to be true)
# In YAML it is a hash with the first entry having key "true ?true"
# representing a list containing the string "- <<YAML.to_i"
# If your YAML object should be a list not a hash you could remove the first line

any_valid_yaml:  from here
a_list:
- or
- anything
- really
#Then mark the end of the YAML document with 
---
#And YAML is done and ignores anything from here on
#Next terminate the ruby here document
YAML

#Now we're in ruby world

@this = "pure ruby"

def anything(ruby)
   "here"
end
meesern
  • 2,518
  • 27
  • 29