]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mailshears/configuration.rb
f9a07bf1f7c81df2b5166991cb9d20dcfb7c2131
[mailshears.git] / lib / mailshears / configuration.rb
1 require 'yaml'
2
3 class Configuration
4
5 USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml'
6 @dict = {}
7
8 def initialize()
9 cfg = default_configuration()
10
11 # Now, load the user configuration which will override the
12 # variables defined above.
13 begin
14 user_config = YAML.load(File.open(USERCONF_PATH))
15
16 # Write our own update() method for Ruby 1.8.
17 user_config.each do |key, value|
18 cfg[key] = value
19 end
20 rescue Errno::ENOENT
21 # If the user config file doesn't exist, whatever.
22 end
23
24 # Convert all of the keys to symbols.
25 cfg = cfg.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
26
27 @dict = cfg
28 end
29
30
31 def method_missing(sym, *args)
32 # Replace all missing method calls with dictionary lookups.
33 return @dict[sym]
34 end
35
36
37 private;
38
39 def default_configuration()
40 d = {}
41
42 d['i_mean_business'] = false
43
44 d['dbhost'] = 'localhost'
45 d['dbport'] = 5432
46 d['dbopts'] = ''
47 d['dbtty'] = ''
48 d['dbuser'] = 'postgres'
49 d['dbpass'] = ''
50 d['dbname'] = 'postfix'
51
52 d['plugins'] = ['dovecot_mailstore', 'roundcube_db']
53
54 d['mail_root'] = '/var/spool/mail/vhosts'
55
56 d['roundcube_dbhost'] = 'localhost'
57 d['roundcube_dbport'] = 5432
58 d['roundcube_dbopts'] = ''
59 d['roundcube_dbtty'] = ''
60 d['roundcube_dbuser'] = 'postgres'
61 d['roundcube_dbpass'] = ''
62 d['roundcube_dbname'] = 'roundcube'
63
64 return d
65 end
66
67 end