Make "postfixadmin" the only default plugin and make dovecot_mail_root safer.
[mailshears.git] / lib / common / configuration.rb
index f9a07bf1f7c81df2b5166991cb9d20dcfb7c2131..02c30d252b796073587ee961011a02ccbebb1936 100644 (file)
@@ -1,17 +1,39 @@
 require 'yaml'
 
+# A configuration object that knows how to read options out of a file
+# in <tt>~/.mailshears.conf.yml</tt>. 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,30 +50,57 @@ 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['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['plugins'] = ['postfixadmin']
+
+    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'] = '/tmp/mailshears-test'
+
+    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