]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Get the new YAML-based configuration working, and update the README.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 19 Apr 2012 14:34:58 +0000 (10:34 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 19 Apr 2012 14:34:58 +0000 (10:34 -0400)
README
lib/mailshears/configuration.rb

diff --git a/README b/README
index 1fd643ce9e8fddcfb3a5f70b238d30496214d5b7..1f065587ccbf25f5d660e6936f1e567f99668fba 100644 (file)
--- a/README
+++ b/README
@@ -35,8 +35,8 @@ Right now, mailshears is targeted at one type of setup:
 
 You put it in a directory somewhere, and run bin/mailshears. To make
 it do anything, you'll need to create a config file. The default is
 
 You put it in a directory somewhere, and run bin/mailshears. To make
 it do anything, you'll need to create a config file. The default is
-stored in lib/default_configuration.rb; I suggest you copy that to
-$HOME/.mailshears.conf.rb and edit it to fit your environment.
+stored in mailshears.example.conf.yml; I suggest you copy that to
+$HOME/.mailshears.conf.yml and edit it to fit your environment.
 
 You'll probably want to set up a cron job to run it every once in a
 while.
 
 You'll probably want to set up a cron job to run it every once in a
 while.
index 1031464a4215c32ee29c2a80e03808a0971a0751..e77969da4ae3bf592dd0232604be39cdcc4afa15 100644 (file)
@@ -3,19 +3,27 @@ require 'yaml'
 class Configuration
 
   USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml'
 class Configuration
 
   USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml'
-  
+  @dict = {}
+
   def initialize()
   def initialize()
-    cfg = self.default_configuration()
+    cfg = default_configuration()
 
     # Now, load the user configuration which will override the
     # variables defined above.
     begin
 
     # 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
+      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
 
       # 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
 
     @dict = cfg
   end