]>
gitweb.michael.orlitzky.com - mailshears.git/blob - configuration.rb
78f5c04f9b57937f13fa523ce2a755eaa59aeedf
3 # A configuration object that knows how to read options out of a file
4 # in <tt>$XDG_CONFIG_HOME/mailshears/mailshears.conf.yml</tt>. The
5 # configuration options can be accessed via methods even though the
6 # internal representation is a hash.
10 # >> cfg = Configuration.new()
11 # >> cfg.i_mean_business()
16 # The hash structure in which we store our configuration options
20 # Initialize a {Configuration} object with the config file at *path*.
22 # @param path [String] the path to the configuration file to
23 # load. We check for a file named "mailshears.conf.yml" in the
24 # user's XDG configuration directory by default.
26 def initialize(path
= nil)
28 # The default path to the user's configuration file.
29 path
= ENV['HOME'] +
'/.config'
30 if ENV.has_key
?('XDG_CONFIG_HOME') then
31 path
= ENV['XDG_CONFIG_HOME']
33 path +
= '/mailshears/mailshears.conf.yml'
36 cfg
= default_configuration()
38 # Now, load the user configuration which will override the
39 # variables defined above.
41 user_config
= YAML
.load(File
.open(path
))
43 # Write our own update() method for Ruby 1.8.
44 user_config
.each
do |key
, value
|
48 # If the user config file doesn't exist, whatever.
51 # Convert all of the keys to symbols.
52 cfg
= cfg
.inject({}){|memo
,(k
,v
)| memo
[k
.to_sym
] = v
; memo
}
58 # Replace all missing method calls with hash lookups. This lets us
59 # retrieve the values in our option hash by using methods named
60 # after the associated keys.
62 # @param sym [Symbol] the method that was called.
64 # @return [Object] the config file value associated with *sym*.
66 def method_missing(sym
, *args
)
74 # A default config hash.
76 # @return [Hash] sensible default configuration values.
78 def default_configuration()
81 d
['i_mean_business'] = false
82 d
['plugins'] = ['postfixadmin']
84 d
['davical_dbhost'] = 'localhost'
85 d
['davical_dbport'] = 5432
86 d
['davical_dbopts'] = ''
87 d
['davical_dbuser'] = 'postgres'
88 d
['davical_dbpass'] = ''
89 d
['davical_dbname'] = 'davical'
91 d
['dovecot_mail_root'] = '/tmp/mailshears-test'
93 d
['postfixadmin_dbhost'] = 'localhost'
94 d
['postfixadmin_dbport'] = 5432
95 d
['postfixadmin_dbopts'] = ''
96 d
['postfixadmin_dbuser'] = 'postgres'
97 d
['postfixadmin_dbpass'] = ''
98 d
['postfixadmin_dbname'] = 'postfixadmin'
100 d
['roundcube_dbhost'] = 'localhost'
101 d
['roundcube_dbport'] = 5432
102 d
['roundcube_dbopts'] = ''
103 d
['roundcube_dbuser'] = 'postgres'
104 d
['roundcube_dbpass'] = ''
105 d
['roundcube_dbname'] = 'roundcube'