Mercurial > hg > soundsoftware-site
comparison lib/redmine/.svn/text-base/configuration.rb.svn-base @ 210:0579821a129a
Update to Redmine trunk rev 4802
author | Chris Cannam |
---|---|
date | Tue, 08 Feb 2011 13:51:46 +0000 |
parents | |
children | 051f544170fe |
comparison
equal
deleted
inserted
replaced
128:07fa8a8b56a8 | 210:0579821a129a |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 module Redmine | |
19 module Configuration | |
20 | |
21 # Configuration default values | |
22 @defaults = { | |
23 'email_delivery' => nil | |
24 } | |
25 | |
26 @config = nil | |
27 | |
28 class << self | |
29 # Loads the Redmine configuration file | |
30 # Valid options: | |
31 # * <tt>:file</tt>: the configuration file to load (default: config/configuration.yml) | |
32 # * <tt>:env</tt>: the environment to load the configuration for (default: Rails.env) | |
33 def load(options={}) | |
34 filename = options[:file] || File.join(Rails.root, 'config', 'configuration.yml') | |
35 env = options[:env] || Rails.env | |
36 | |
37 @config = @defaults.dup | |
38 | |
39 load_deprecated_email_configuration(env) | |
40 if File.file?(filename) | |
41 @config.merge!(load_from_yaml(filename, env)) | |
42 end | |
43 | |
44 # Compatibility mode for those who copy email.yml over configuration.yml | |
45 %w(delivery_method smtp_settings sendmail_settings).each do |key| | |
46 if value = @config.delete(key) | |
47 @config['email_delivery'] ||= {} | |
48 @config['email_delivery'][key] = value | |
49 end | |
50 end | |
51 | |
52 if @config['email_delivery'] | |
53 ActionMailer::Base.perform_deliveries = true | |
54 @config['email_delivery'].each do |k, v| | |
55 v.symbolize_keys! if v.respond_to?(:symbolize_keys!) | |
56 ActionMailer::Base.send("#{k}=", v) | |
57 end | |
58 end | |
59 | |
60 @config | |
61 end | |
62 | |
63 # Returns a configuration setting | |
64 def [](name) | |
65 load unless @config | |
66 @config[name] | |
67 end | |
68 | |
69 private | |
70 | |
71 def load_from_yaml(filename, env) | |
72 yaml = YAML::load_file(filename) | |
73 conf = {} | |
74 if yaml.is_a?(Hash) | |
75 if yaml['default'] | |
76 conf.merge!(yaml['default']) | |
77 end | |
78 if yaml[env] | |
79 conf.merge!(yaml[env]) | |
80 end | |
81 else | |
82 $stderr.puts "#{filename} is not a valid Redmine configuration file" | |
83 exit 1 | |
84 end | |
85 conf | |
86 end | |
87 | |
88 def load_deprecated_email_configuration(env) | |
89 deprecated_email_conf = File.join(Rails.root, 'config', 'email.yml') | |
90 if File.file?(deprecated_email_conf) | |
91 warn "Storing outgoing emails configuration in config/email.yml is deprecated. You should now store it in config/configuration.yml using the email_delivery setting." | |
92 @config.merge!({'email_delivery' => load_from_yaml(deprecated_email_conf, env)}) | |
93 end | |
94 end | |
95 end | |
96 end | |
97 end |