X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fcommon%2Fconfiguration.rb;h=78f5c04f9b57937f13fa523ce2a755eaa59aeedf;hb=HEAD;hp=f04d018d70fa572bbbc6c6d418e6f9e73225b26a;hpb=d078dd8216e0cd101a945dfac448bde9f7d73d1a;p=mailshears.git
diff --git a/lib/common/configuration.rb b/lib/common/configuration.rb
index f04d018..78f5c04 100644
--- a/lib/common/configuration.rb
+++ b/lib/common/configuration.rb
@@ -1,9 +1,9 @@
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.
+# in $XDG_CONFIG_HOME/mailshears/mailshears.conf.yml. The
+# configuration options can be accessed via methods even though the
+# internal representation is a hash.
#
# === Examples
#
@@ -13,21 +13,26 @@ require 'yaml'
#
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.
+ # load. We check for a file named "mailshears.conf.yml" in the
+ # user's XDG configuration directory by default.
#
- def initialize(path = USERCONF_PATH)
+ def initialize(path = nil)
+ if path.nil? then
+ # The default path to the user's configuration file.
+ path = ENV['HOME'] + '/.config'
+ if ENV.has_key?('XDG_CONFIG_HOME') then
+ path = ENV['XDG_CONFIG_HOME']
+ end
+ path += '/mailshears/mailshears.conf.yml'
+ end
+
cfg = default_configuration()
# Now, load the user configuration which will override the