simplify config loading
This commit is contained in:
parent
92b6e6e28e
commit
8b83787252
2 changed files with 7 additions and 14 deletions
|
@ -51,16 +51,16 @@ class FoodsoftConfig
|
||||||
# Taken from environment variable +FOODSOFT_APP_CONFIG+,
|
# Taken from environment variable +FOODSOFT_APP_CONFIG+,
|
||||||
# or else +config/app_config.yml+.
|
# or else +config/app_config.yml+.
|
||||||
APP_CONFIG_FILE = ENV['FOODSOFT_APP_CONFIG'] || '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
|
# Loaded configuration
|
||||||
APP_CONFIG = ActiveSupport::HashWithIndifferentAccess.new(
|
APP_CONFIG = ActiveSupport::HashWithIndifferentAccess.new
|
||||||
YAML.load(File.read(File.expand_path(APP_CONFIG_FILE, Rails.root)))
|
|
||||||
)
|
|
||||||
|
|
||||||
class << self
|
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
|
# Gather program-default configuration
|
||||||
self.default_config = get_default_config
|
self.default_config = get_default_config
|
||||||
# Load initial config from development or production
|
# Load initial config from development or production
|
||||||
|
@ -187,13 +187,6 @@ class FoodsoftConfig
|
||||||
# @return [Hash] Default configuration values
|
# @return [Hash] Default configuration values
|
||||||
mattr_accessor :default_config
|
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
|
private
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ RSpec.configure do |config|
|
||||||
# reload foodsoft configuration, so that tests can use FoodsoftConfig.config[:foo]=x
|
# reload foodsoft configuration, so that tests can use FoodsoftConfig.config[:foo]=x
|
||||||
# without messing up tests run after that
|
# without messing up tests run after that
|
||||||
config.before(:each) do
|
config.before(:each) do
|
||||||
FoodsoftConfig.send :reload!
|
FoodsoftConfig.init
|
||||||
end
|
end
|
||||||
|
|
||||||
# If true, the base class of anonymous controllers will be inferred
|
# If true, the base class of anonymous controllers will be inferred
|
||||||
|
|
Loading…
Reference in a new issue