]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Add a Configuration class which loads a user YAML file instead of Ruby code.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 19 Apr 2012 13:55:22 +0000 (09:55 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 19 Apr 2012 13:55:22 +0000 (09:55 -0400)
lib/mailshears/configuration.rb [new file with mode: 0644]

diff --git a/lib/mailshears/configuration.rb b/lib/mailshears/configuration.rb
new file mode 100644 (file)
index 0000000..1031464
--- /dev/null
@@ -0,0 +1,59 @@
+require 'yaml'
+
+class Configuration
+
+  USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml'
+  
+  def initialize()
+    cfg = self.default_configuration()
+
+    # Now, load the user configuration which will override the
+    # variables defined above.
+    begin
+      user_config = Config.new(YAML.load(File.open(USERCONF_PATH)))
+      cfg.update!(user_config)
+    rescue LoadError
+      # If the user config file doesn't exist, whatever.
+    end
+
+    @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