caeab92a655a8dd92aa9b4dfa8784b2edc64ff14
[mailshears.git] / lib / common / configuration.rb
1 require 'yaml'
2
3 class Configuration
4
5 USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml'
6 @dict = {}
7
8 def initialize(path = USERCONF_PATH)
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(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 d['plugins'] = ['agendav',
44 'davical',
45 'dovecot',
46 'postfixadmin',
47 'roundcube']
48
49 d['agendav_dbhost'] = 'localhost'
50 d['agendav_dbport'] = 5432
51 d['agendav_dbopts'] = ''
52 d['agendav_dbtty'] = ''
53 d['agendav_dbuser'] = 'postgres'
54 d['agendav_dbpass'] = ''
55 d['agendav_dbname'] = 'agendav'
56
57 d['davical_dbhost'] = 'localhost'
58 d['davical_dbport'] = 5432
59 d['davical_dbopts'] = ''
60 d['davical_dbtty'] = ''
61 d['davical_dbuser'] = 'postgres'
62 d['davical_dbpass'] = ''
63 d['davical_dbname'] = 'davical'
64
65 d['dovecot_mail_root'] = '/var/spool/mail/vhosts'
66
67 d['postfixadmin_dbhost'] = 'localhost'
68 d['postfixadmin_dbport'] = 5432
69 d['postfixadmin_dbopts'] = ''
70 d['postfixadmin_dbtty'] = ''
71 d['postfixadmin_dbuser'] = 'postgres'
72 d['postfixadmin_dbpass'] = ''
73 d['postfixadmin_dbname'] = 'postfixadmin'
74
75 d['roundcube_dbhost'] = 'localhost'
76 d['roundcube_dbport'] = 5432
77 d['roundcube_dbopts'] = ''
78 d['roundcube_dbtty'] = ''
79 d['roundcube_dbuser'] = 'postgres'
80 d['roundcube_dbpass'] = ''
81 d['roundcube_dbname'] = 'roundcube'
82
83 return d
84 end
85
86 end