Add a Configuration class which loads a user YAML file instead of Ruby code.
[mailshears.git] / lib / mailshears / configuration.rb
1 require 'yaml'
2
3 class Configuration
4
5 USERCONF_PATH = ENV['HOME'] + '/.mailshears.conf.yml'
6
7 def initialize()
8 cfg = self.default_configuration()
9
10 # Now, load the user configuration which will override the
11 # variables defined above.
12 begin
13 user_config = Config.new(YAML.load(File.open(USERCONF_PATH)))
14 cfg.update!(user_config)
15 rescue LoadError
16 # If the user config file doesn't exist, whatever.
17 end
18
19 @dict = cfg
20 end
21
22
23 def method_missing(sym, *args)
24 # Replace all missing method calls with dictionary lookups.
25 return @dict[sym]
26 end
27
28
29 private;
30
31 def default_configuration()
32 d = {}
33
34 d['i_mean_business'] = false
35
36 d['dbhost'] = 'localhost'
37 d['dbport'] = 5432
38 d['dbopts'] = ''
39 d['dbtty'] = ''
40 d['dbuser'] = 'postgres'
41 d['dbpass'] = ''
42 d['dbname'] = 'postfix'
43
44 d['plugins'] = ['dovecot_mailstore', 'roundcube_db']
45
46 d['mail_root'] = '/var/spool/mail/vhosts'
47
48 d['roundcube_dbhost'] = 'localhost'
49 d['roundcube_dbport'] = 5432
50 d['roundcube_dbopts'] = ''
51 d['roundcube_dbtty'] = ''
52 d['roundcube_dbuser'] = 'postgres'
53 d['roundcube_dbpass'] = ''
54 d['roundcube_dbname'] = 'roundcube'
55
56 return d
57 end
58
59 end