X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fconfiguration.rb;h=b810b02f86c9d44711fbdae7836c391035d72c80;hp=43ef03b3e726f5fd694b44c6bac1a4416a0e5d52;hb=df4e02ebf6a4e28a58abcb298a4442a245ad0b15;hpb=7f8654ed6582062a295e1be75ae70e99de41b323 diff --git a/lib/common/configuration.rb b/lib/common/configuration.rb index 43ef03b..b810b02 100644 --- a/lib/common/configuration.rb +++ b/lib/common/configuration.rb @@ -1,17 +1,39 @@ require 'yaml' +# A configuration object that knows how to read options out of a file +# in ~/.mailshears.conf.yml. The configuration options can be +# accessed via methods even though the internal representation is a +# hash. +# +# === Examples +# +# >> cfg = Configuration.new() +# >> cfg.i_mean_business() +# => true +# class Configuration + # The default path to the user's configuration file. USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml' + + # The hash structure in which we store our configuration options + # internally. @dict = {} - def initialize() + + # Initialize a {Configuration} object with the config file at *path*. + # + # @param path [String] the path to the configuration file to + # load. We check for a file named ".mailshears.conf.yml" in the + # user's home directory by default. + # + 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(USERCONF_PATH)) + user_config = YAML.load(File.open(path)) # Write our own update() method for Ruby 1.8. user_config.each do |key, value| @@ -28,38 +50,35 @@ class Configuration end + # Replace all missing method calls with hash lookups. This lets us + # retrieve the values in our option hash by using methods named + # after the associated keys. + # + # @param sym [Symbol] the method that was called. + # + # @return [Object] the config file value associated with *sym*. + # def method_missing(sym, *args) - # Replace all missing method calls with dictionary lookups. return @dict[sym] end private; + + # A default config hash. + # + # @return [Hash] sensible default configuration values. + # def default_configuration() d = {} d['i_mean_business'] = false - - 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['plugins'] = ['postfixadmin', 'dovecot', 'roundcube'] - - 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' + d['plugins'] = ['agendav', + 'davical', + 'dovecot', + 'postfixadmin', + 'roundcube'] d['agendav_dbhost'] = 'localhost' d['agendav_dbport'] = 5432 @@ -77,6 +96,24 @@ class Configuration 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