]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/configuration.rb
3 # A configuration object that knows how to read options out of a file
4 # in <tt>~/.mailshears.conf.yml</tt>. The configuration options can be
5 # accessed via methods even though the internal representation is a
10 # >> cfg = Configuration.new()
11 # >> cfg.i_mean_business()
16 # The default path to the user's configuration file.
17 USERCONF_PATH
= ENV['HOME'] +
'/.mailshears.conf.yml'
19 # The hash structure in which we store our configuration options
24 # Initialize a {Configuration} object with the config file at *path*.
26 # @param path [String] the path to the configuration file to
27 # load. We check for a file named ".mailshears.conf.yml" in the
28 # user's home directory by default.
30 def initialize(path
= USERCONF_PATH
)
31 cfg
= default_configuration()
33 # Now, load the user configuration which will override the
34 # variables defined above.
36 user_config
= YAML
.load(File
.open(path
))
38 # Write our own update() method for Ruby 1.8.
39 user_config
.each
do |key
, value
|
43 # If the user config file doesn't exist, whatever.
46 # Convert all of the keys to symbols.
47 cfg
= cfg
.inject({}){|memo
,(k
,v
)| memo
[k
.to_sym
] = v
; memo
}
53 # Replace all missing method calls with hash lookups. This lets us
54 # retrieve the values in our option hash by using methods named
55 # after the associated keys.
57 # @param sym [Symbol] the method that was called.
59 # @return [Object] the config file value associated with *sym*.
61 def method_missing(sym
, *args
)
69 # A default config hash.
71 # @return [Hash] sensible default configuration values.
73 def default_configuration()
76 d
['i_mean_business'] = false
77 d
['plugins'] = ['postfixadmin']
79 d
['agendav_dbhost'] = 'localhost'
80 d
['agendav_dbport'] = 5432
81 d
['agendav_dbopts'] = ''
82 d
['agendav_dbtty'] = ''
83 d
['agendav_dbuser'] = 'postgres'
84 d
['agendav_dbpass'] = ''
85 d
['agendav_dbname'] = 'agendav'
87 d
['davical_dbhost'] = 'localhost'
88 d
['davical_dbport'] = 5432
89 d
['davical_dbopts'] = ''
90 d
['davical_dbtty'] = ''
91 d
['davical_dbuser'] = 'postgres'
92 d
['davical_dbpass'] = ''
93 d
['davical_dbname'] = 'davical'
95 d
['dovecot_mail_root'] = '/tmp/mailshears-test'
97 d
['postfixadmin_dbhost'] = 'localhost'
98 d
['postfixadmin_dbport'] = 5432
99 d
['postfixadmin_dbopts'] = ''
100 d
['postfixadmin_dbtty'] = ''
101 d
['postfixadmin_dbuser'] = 'postgres'
102 d
['postfixadmin_dbpass'] = ''
103 d
['postfixadmin_dbname'] = 'postfixadmin'
105 d
['roundcube_dbhost'] = 'localhost'
106 d
['roundcube_dbport'] = 5432
107 d
['roundcube_dbopts'] = ''
108 d
['roundcube_dbtty'] = ''
109 d
['roundcube_dbuser'] = 'postgres'
110 d
['roundcube_dbpass'] = ''
111 d
['roundcube_dbname'] = 'roundcube'