X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fconfiguration.rb;h=02c30d252b796073587ee961011a02ccbebb1936;hp=caeab92a655a8dd92aa9b4dfa8784b2edc64ff14;hb=5bf27259563a3dda6425dc794722273cc29b69f7;hpb=c3d89b5da74b7f9eadd89242150b4d7c3b758212 diff --git a/lib/common/configuration.rb b/lib/common/configuration.rb index caeab92..02c30d2 100644 --- a/lib/common/configuration.rb +++ b/lib/common/configuration.rb @@ -1,10 +1,32 @@ 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 = {} + + # 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() @@ -28,23 +50,31 @@ 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['plugins'] = ['agendav', - 'davical', - 'dovecot', - 'postfixadmin', - 'roundcube'] + d['plugins'] = ['postfixadmin'] d['agendav_dbhost'] = 'localhost' d['agendav_dbport'] = 5432 @@ -62,7 +92,7 @@ class Configuration d['davical_dbpass'] = '' d['davical_dbname'] = 'davical' - d['dovecot_mail_root'] = '/var/spool/mail/vhosts' + d['dovecot_mail_root'] = '/tmp/mailshears-test' d['postfixadmin_dbhost'] = 'localhost' d['postfixadmin_dbport'] = 5432