conker 0.12.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/conker.gemspec +1 -1
  2. data/lib/conker.rb +18 -5
  3. metadata +1 -1
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
2
2
  s.name = 'conker'
3
3
  s.authors = ['Sam Stokes', 'Conrad Irwin', 'Lee Mallabone', 'Martin Kleppmann']
4
4
  s.email = 'supportive@rapportive.com'
5
- s.version = '0.12.1'
5
+ s.version = '0.12.2'
6
6
  s.summary = %q{Conker will conquer your config.}
7
7
  s.description = "Configuration library."
8
8
  s.homepage = "https://github.com/rapportive/conker"
@@ -42,7 +42,7 @@ module Conker
42
42
  # Parse a multi-key hash into globals and raise an informative error message on failure.
43
43
  def setup_config!(current_env, *args)
44
44
  declarations = args.extract_options!
45
- values = values_hash(args[0])
45
+ values = values_hash(current_env, args[0])
46
46
 
47
47
  setup_constants(current_env, declarations, values)
48
48
  end
@@ -58,9 +58,10 @@ module Conker
58
58
  def setup_rack_environment!(*args)
59
59
  ENV['RACK_ENV'] ||= 'development'
60
60
  set_constant(:RACK_ENV, ENV['RACK_ENV'])
61
+ current_env = get_constant(:RACK_ENV)
61
62
 
62
63
  declarations = args.extract_options!
63
- values = values_hash(args[0])
64
+ values = values_hash(current_env, args[0])
64
65
 
65
66
  if declarations.key?('RACK_ENV') || declarations.key?(:RACK_ENV)
66
67
  raise Error, "No need to declare RACK_ENV; please remove it to avoid confusion!"
@@ -69,7 +70,7 @@ module Conker
69
70
  raise "RACK_ENV differs between environment (#{env}) and config (#{conf})! Please remove it from your config."
70
71
  end
71
72
 
72
- setup_constants(ENV['RACK_ENV'], declarations, values)
73
+ setup_constants(current_env, declarations, values)
73
74
  end
74
75
 
75
76
  # Declare an environment variable that is required to be defined in the
@@ -126,10 +127,18 @@ module Conker
126
127
  end
127
128
 
128
129
  private
129
- def values_hash(values)
130
+ def values_hash(current_env, values)
130
131
  case values
131
132
  when Hash; values
132
- when String; require 'yaml'; YAML.parse_file(values).to_ruby
133
+ when String
134
+ if File.exist?(values)
135
+ require 'yaml'
136
+ YAML.parse_file(values).to_ruby
137
+ elsif 'production' == current_env.to_s
138
+ raise Error, "Missing config file #{values}"
139
+ else
140
+ {}
141
+ end
133
142
  else; ENV
134
143
  end
135
144
  end
@@ -153,6 +162,10 @@ module Conker
153
162
  def set_constant(varname, value)
154
163
  Kernel.const_set(varname, value)
155
164
  end
165
+
166
+ def get_constant(varname)
167
+ Kernel.const_get(varname)
168
+ end
156
169
  end
157
170
 
158
171
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: