Skip to content

Commit

Permalink
Shouldn't be possible to use confs and ext-less confs.
Browse files Browse the repository at this point in the history
  • Loading branch information
iced committed Jul 20, 2012
1 parent 0cadbcb commit db8331e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.2
0.3.3
18 changes: 10 additions & 8 deletions lib/iron_core/client.rb
Expand Up @@ -26,7 +26,7 @@ def initialize(company, product, options = {}, default_options = {}, extra_optio
end

@env = options[:env] || options['env']
@env ||= ENV[company.upcase + '_' + product.upcase + '_ENV'] || ENV[product.upcase + '_ENV'] || ENV[company.upcase + '_ENV']
@env ||= ENV[company.upcase + '_' + product.upcase + '_ENV'] || ENV[company.upcase + '_ENV']

IronCore::Logger.info 'IronCore', "Setting env to '#{@env}'" unless @env.nil?

Expand All @@ -35,25 +35,23 @@ def initialize(company, product, options = {}, default_options = {}, extra_optio
load_from_config(company, product, options[:config] || options['config'])

load_from_config(company, product, ENV[company.upcase + '_' + product.upcase + '_CONFIG'])
load_from_config(company, product, ENV[product.upcase + '_CONFIG'])
load_from_config(company, product, ENV[company.upcase + '_CONFIG'])

load_from_env(company.upcase + '_' + product.upcase)
load_from_env(product.upcase)
load_from_env(company.upcase)

suffixes = []

unless @env.nil?
suffixes << "-#{env}"
suffixes << "_#{env}"
suffixes << "-#{@env}"
suffixes << "_#{@env}"
end

suffixes << ''

suffixes.each do |suffix|
['.json', ''].each do |ext|
["#{company}-#{product}", "#{company}_#{product}", product, company].each do |config_base|
['.json'].each do |ext|
["#{company}-#{product}", "#{company}_#{product}", company].each do |config_base|
load_from_config(company, product, "#{config_base}#{suffix}#{ext}")
load_from_config(company, product, ".#{config_base}#{suffix}#{ext}")
load_from_config(company, product, "~/#{config_base}#{suffix}#{ext}")
Expand Down Expand Up @@ -110,12 +108,16 @@ def load_from_config(company, product, config_file)
return if config_file.nil?

if File.exists?(File.expand_path(config_file))
config_data = '{}'

begin
config = JSON.load(File.read(File.expand_path(config_file)))
config_data = File.read(File.expand_path(config_file))
rescue
return
end

config = JSON.parse(config_data)

unless @env.nil?
load_from_hash(config_file, get_sub_hash(config, [@env, "#{company}_#{product}"]))
load_from_hash(config_file, get_sub_hash(config, [@env, company, product]))
Expand Down

0 comments on commit db8331e

Please sign in to comment.