X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fconfiguration.rb;fp=lib%2Fcommon%2Fconfiguration.rb;h=f9a07bf1f7c81df2b5166991cb9d20dcfb7c2131;hp=0000000000000000000000000000000000000000;hb=c6cab6b71770d14dad1115db90a00b990c44a58d;hpb=150ee5398c17acca8ef03b3cc48b3aa7bc1b0035 diff --git a/lib/common/configuration.rb b/lib/common/configuration.rb new file mode 100644 index 0000000..f9a07bf --- /dev/null +++ b/lib/common/configuration.rb @@ -0,0 +1,67 @@ +require 'yaml' + +class Configuration + + USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml' + @dict = {} + + def initialize() + cfg = default_configuration() + + # Now, load the user configuration which will override the + # variables defined above. + begin + user_config = YAML.load(File.open(USERCONF_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['dbhost'] = 'localhost' + d['dbport'] = 5432 + d['dbopts'] = '' + d['dbtty'] = '' + d['dbuser'] = 'postgres' + d['dbpass'] = '' + d['dbname'] = 'postfix' + + d['plugins'] = ['dovecot_mailstore', 'roundcube_db'] + + d['mail_root'] = '/var/spool/mail/vhosts' + + 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