simplify config loading

This commit is contained in:
wvengen 2014-09-11 16:40:09 +02:00
parent 92b6e6e28e
commit 8b83787252
2 changed files with 7 additions and 14 deletions

View file

@ -51,16 +51,16 @@ class FoodsoftConfig
# Taken from environment variable +FOODSOFT_APP_CONFIG+,
# or else +config/app_config.yml+.
APP_CONFIG_FILE = ENV['FOODSOFT_APP_CONFIG'] || 'config/app_config.yml'
# Rails.logger isn't ready yet - and we don't want to litter rspec invocation with this msg
puts "-> Loading app configuration from #{APP_CONFIG_FILE}" unless defined? RSpec
# Loaded configuration
APP_CONFIG = ActiveSupport::HashWithIndifferentAccess.new(
YAML.load(File.read(File.expand_path(APP_CONFIG_FILE, Rails.root)))
)
APP_CONFIG = ActiveSupport::HashWithIndifferentAccess.new
class << self
def init
# Load and initialize foodcoop configuration file.
# @param filename [String] Override configuration file
def init(filename = APP_CONFIG_FILE)
Rails.logger.info "Loading app configuration from #{APP_CONFIG_FILE}"
APP_CONFIG.clear.merge! YAML.load(File.read(File.expand_path(filename, Rails.root)))
# Gather program-default configuration
self.default_config = get_default_config
# Load initial config from development or production
@ -187,13 +187,6 @@ class FoodsoftConfig
# @return [Hash] Default configuration values
mattr_accessor :default_config
# Reload original configuration file, e.g. in between tests.
# @param filename [String] Override configuration file
def reload!(filename = APP_CONFIG_FILE)
APP_CONFIG.clear.merge! YAML.load(File.read(File.expand_path(filename, Rails.root)))
init
end
private

View file

@ -42,7 +42,7 @@ RSpec.configure do |config|
# reload foodsoft configuration, so that tests can use FoodsoftConfig.config[:foo]=x
# without messing up tests run after that
config.before(:each) do
FoodsoftConfig.send :reload!
FoodsoftConfig.init
end
# If true, the base class of anonymous controllers will be inferred