lib/conker.rb in conker-0.12.1 vs lib/conker.rb in conker-0.12.2

- old
+ new

@@ -40,11 +40,11 @@ class << self # Parse a multi-key hash into globals and raise an informative error message on failure. def setup_config!(current_env, *args) declarations = args.extract_options! - values = values_hash(args[0]) + values = values_hash(current_env, args[0]) setup_constants(current_env, declarations, values) end # Like setup_config! but uses ENV['RACK_ENV'] || 'development' as the @@ -56,22 +56,23 @@ # only from the environment variable, for compatibility with other code # (e.g. Sinatra) that depends directly on the environment variable. def setup_rack_environment!(*args) ENV['RACK_ENV'] ||= 'development' set_constant(:RACK_ENV, ENV['RACK_ENV']) + current_env = get_constant(:RACK_ENV) declarations = args.extract_options! - values = values_hash(args[0]) + values = values_hash(current_env, args[0]) if declarations.key?('RACK_ENV') || declarations.key?(:RACK_ENV) raise Error, "No need to declare RACK_ENV; please remove it to avoid confusion!" end if ENV.key?('RACK_ENV') && values.key?('RACK_ENV') && (env = ENV['RACK_ENV']) != (conf = values['RACK_ENV']) raise "RACK_ENV differs between environment (#{env}) and config (#{conf})! Please remove it from your config." end - setup_constants(ENV['RACK_ENV'], declarations, values) + setup_constants(current_env, declarations, values) end # Declare an environment variable that is required to be defined in the # production environment, and defaults to other values in the test or # development environments. @@ -124,14 +125,22 @@ def optional(declaration_opts = {}) VariableDeclaration.new(declaration_opts) end private - def values_hash(values) + def values_hash(current_env, values) case values when Hash; values - when String; require 'yaml'; YAML.parse_file(values).to_ruby + when String + if File.exist?(values) + require 'yaml' + YAML.parse_file(values).to_ruby + elsif 'production' == current_env.to_s + raise Error, "Missing config file #{values}" + else + {} + end else; ENV end end def setup_constants(current_env, declarations, values) @@ -150,9 +159,13 @@ raise Error, error_message unless errors.empty? end def set_constant(varname, value) Kernel.const_set(varname, value) + end + + def get_constant(varname) + Kernel.const_get(varname) end end class VariableDeclaration