Module: Redmine::Configuration

Defined in:
lib/redmine/configuration.rb

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Returns a configuration setting


75
76
77
78
# File 'lib/redmine/configuration.rb', line 75

def [](name)
  load unless @config
  @config[name]
end

.load(options = {}) ⇒ Object

Loads the Redmine configuration file Valid options:

  • :file: the configuration file to load (default: config/configuration.yml)

  • :env: the environment to load the configuration for (default: Rails.env)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/redmine/configuration.rb', line 37

def load(options={})
  filename = options[:file] || File.join(Rails.root, 'config', 'configuration.yml')
  env = options[:env] || Rails.env

  @config = @defaults.dup

  load_deprecated_email_configuration(env)
  if File.file?(filename)
    @config.merge!(load_from_yaml(filename, env))
  end

  # Compatibility mode for those who copy email.yml over configuration.yml
  %w(delivery_method smtp_settings sendmail_settings).each do |key|
    if value = @config.delete(key)
      @config['email_delivery'] ||= {}
      @config['email_delivery'][key] = value
    end
  end

  if @config['email_delivery']
    ActionMailer::Base.perform_deliveries = true
    @config['email_delivery'].each do |k, v|
      # Comprehensive error message for those who used async_smtp and async_sendmail
      # delivery methods that are removed in Redmine 4.0.
      if k == 'delivery_method' && v.to_s =~ /\Aasync_(.+)/
        abort "Redmine now uses ActiveJob to send emails asynchronously and the :#{v} delivery method is no longer available.\n" +
          "Please update your config/configuration.yml to use :#$1 delivery method instead."
      end
      v.symbolize_keys! if v.respond_to?(:symbolize_keys!)
      ActionMailer::Base.send("#{k}=", v)
    end
  end

  check_regular_expressions
  @config
end

.with(settings) ⇒ Object

Yields a block with the specified hash configuration settings


81
82
83
84
85
86
87
88
# File 'lib/redmine/configuration.rb', line 81

def with(settings)
  settings.stringify_keys!
  load unless @config
  was = settings.keys.inject({}) {|h,v| h[v] = @config[v]; h}
  @config.merge! settings
  yield if block_given?
  @config.merge! was
end