warn and exit if there's no config at all
This commit is contained in:
parent
47dd3ba076
commit
0c5bdece5a
2 changed files with 26 additions and 3 deletions
|
|
@ -6,11 +6,16 @@ class AppConfig
|
|||
|
||||
cattr_accessor :config_vars
|
||||
cattr_accessor :base_file_path
|
||||
cattr_accessor :file_path
|
||||
|
||||
def self.base_file_path
|
||||
@@base_file_path || File.join(Rails.root, "config", "app_base.yml")
|
||||
end
|
||||
|
||||
def self.file_path
|
||||
@@file_path || File.join(Rails.root, "config", "app.yml")
|
||||
end
|
||||
|
||||
def self.[](key)
|
||||
config_vars[key]
|
||||
end
|
||||
|
|
@ -38,8 +43,8 @@ class AppConfig
|
|||
$stderr.puts "OH NO! Required file #{base_file_path} doesn't exist! Did you move it?"
|
||||
all_envs = {}
|
||||
end
|
||||
if File.exist? "#{Rails.root}/config/app.yml"
|
||||
all_envs_custom = load_config_yaml "#{Rails.root}/config/app.yml"
|
||||
if File.exist?(file_path)
|
||||
all_envs_custom = load_config_yaml(file_path)
|
||||
all_envs.deep_merge!(all_envs_custom)
|
||||
elsif File.exist? "#{Rails.root}/config/app_config.yml"
|
||||
all_envs_custom = load_config_yaml "#{Rails.root}/config/app_config.yml"
|
||||
|
|
@ -51,6 +56,12 @@ class AppConfig
|
|||
end
|
||||
end
|
||||
|
||||
# Is there a config at all?
|
||||
unless all_envs['default']
|
||||
$stderr.puts "What did you do? There's no config at all!"
|
||||
Process.exit(false)
|
||||
end
|
||||
|
||||
env = env.to_s
|
||||
if all_envs[env]
|
||||
self.config_vars = all_envs['default'].merge(all_envs[env]).symbolize_keys
|
||||
|
|
|
|||
|
|
@ -32,11 +32,23 @@ describe AppConfig do
|
|||
end
|
||||
it "prints error if base file is missing" do
|
||||
AppConfig.base_file_path = "/no/such/file"
|
||||
AppConfig.file_path = File.join(Rails.root, "config", "app_base.yml")
|
||||
|
||||
AppConfig.load_config_for_environment(:test)
|
||||
$stderr.rewind
|
||||
$stderr.string.chomp.should_not be_blank
|
||||
end
|
||||
it "prints error and exits if there's no config at all" do
|
||||
AppConfig.base_file_path = "/no/such/file"
|
||||
AppConfig.file_path = "/no/such/file"
|
||||
|
||||
lambda {
|
||||
AppConfig.load_config_for_environment(:test)
|
||||
}.should raise_error SystemExit
|
||||
|
||||
$stderr.rewind
|
||||
$stderr.string.chomp.should_not be_blank
|
||||
end
|
||||
end
|
||||
describe ".generate_pod_uri" do
|
||||
describe "when pod_url is prefixed with protocol" do
|
||||
|
|
@ -64,4 +76,4 @@ describe AppConfig do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue