require 'yaml' class Configuration USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml' @dict = {} def initialize(path = USERCONF_PATH) cfg = default_configuration() # Now, load the user configuration which will override the # variables defined above. begin user_config = YAML.load(File.open(path)) # Write our own update() method for Ruby 1.8. user_config.each do |key, value| cfg[key] = value end rescue Errno::ENOENT # If the user config file doesn't exist, whatever. end # Convert all of the keys to symbols. cfg = cfg.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} @dict = cfg end def method_missing(sym, *args) # Replace all missing method calls with dictionary lookups. return @dict[sym] end private; def default_configuration() d = {} d['i_mean_business'] = false d['plugins'] = ['agendav', 'davical', 'dovecot', 'postfixadmin', 'roundcube'] d['agendav_dbhost'] = 'localhost' d['agendav_dbport'] = 5432 d['agendav_dbopts'] = '' d['agendav_dbtty'] = '' d['agendav_dbuser'] = 'postgres' d['agendav_dbpass'] = '' d['agendav_dbname'] = 'agendav' d['davical_dbhost'] = 'localhost' d['davical_dbport'] = 5432 d['davical_dbopts'] = '' d['davical_dbtty'] = '' d['davical_dbuser'] = 'postgres' d['davical_dbpass'] = '' d['davical_dbname'] = 'davical' d['dovecot_mail_root'] = '/var/spool/mail/vhosts' d['postfixadmin_dbhost'] = 'localhost' d['postfixadmin_dbport'] = 5432 d['postfixadmin_dbopts'] = '' d['postfixadmin_dbtty'] = '' d['postfixadmin_dbuser'] = 'postgres' d['postfixadmin_dbpass'] = '' d['postfixadmin_dbname'] = 'postfixadmin' d['roundcube_dbhost'] = 'localhost' d['roundcube_dbport'] = 5432 d['roundcube_dbopts'] = '' d['roundcube_dbtty'] = '' d['roundcube_dbuser'] = 'postgres' d['roundcube_dbpass'] = '' d['roundcube_dbname'] = 'roundcube' return d end end