configatron 2.11.0 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04b9056694b0e769316768fd1c635c150c0193ed
4
- data.tar.gz: bc9506af875b3ad87c9f76c5ddc7bbc32c4086f5
3
+ metadata.gz: 7ad275e874cd8d84144f386f237517860fdfe0d9
4
+ data.tar.gz: 05020e5145f79ee869a6738a75b4ac3d14db2cf7
5
5
  SHA512:
6
- metadata.gz: 49bbd0375bd4f9c2fa2eae9568493e6c85a37a1d7a56ee9296d6c40c00961c20f03a57187d5b0bc4257de4143d53f5e92abae6c911688f829213ecef52389686
7
- data.tar.gz: 00912c56e963c7f869c756a40669e96280dc4bed428eaa76d3eadc82e0e54ab3bb72ed07e3ff7bb393d094c53c6ac35c2fd73fb81e64faffd499a6f00f6a3f25
6
+ metadata.gz: 15c5147856dd716772faf24d8ddfec36132fe55813988475528dcf2faf3e2221525dc87fb1be027f15a82bb9dd922f8c0cc01921efd22f25c8b868da86d851d1
7
+ data.tar.gz: ba5f57da5bcc09e13ba7bae188e94ecdcea75de67ca248cee9fd208709b02390d1b2e2cab8a9df59dab37cd0c85fd657dec77dc18da5a700cd1e357830999994
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- configatron (2.11.0)
4
+ configatron (2.12.0)
5
5
  yamler (>= 0.1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -224,19 +224,19 @@ Enjoy!
224
224
  * Kurtis Rainbolt-Greene
225
225
  * Rob Sanheim
226
226
  * Cody Maggard
227
+ * Greg Brockman
227
228
  * Jean-Denis Vauguet
228
- * chatgris
229
- * Mat Brown
230
- * Gleb Pomykalov
231
229
  * Torsten Schönebaum
230
+ * Mat Brown
232
231
  * Simon Menke
232
+ * chatgris
233
+ * Gleb Pomykalov
233
234
  * Casper Gripenberg
234
235
  * mattelacchiato
235
236
  * Artiom Diomin
236
- * Rick Fletcher
237
237
  * Tim Riley
238
+ * Rick Fletcher
238
239
  * joe miller
239
- * Dan Pickett
240
240
  * Brandon Dimcheff
241
- * Greg Brockman
241
+ * Dan Pickett
242
242
  * Josh Nichols
@@ -7,7 +7,9 @@ class Configatron
7
7
  alias_method :send!, :send
8
8
 
9
9
  class << self
10
-
10
+
11
+ attr_accessor :strict
12
+
11
13
  def log
12
14
  unless @logger
13
15
  if defined?(::Rails)
@@ -17,7 +19,10 @@ class Configatron
17
19
  end
18
20
  return @logger
19
21
  end
20
-
22
+
23
+ def reset!
24
+ @strict = false
25
+ end
21
26
  end
22
27
 
23
28
  def initialize # :nodoc:
@@ -37,6 +42,7 @@ class Configatron
37
42
 
38
43
  # Removes ALL configuration parameters
39
44
  def reset!
45
+ self.class.reset!
40
46
  @_store = {:default => Configatron::Store.new}
41
47
  end
42
48
 
@@ -67,15 +67,7 @@ class Configatron
67
67
  end
68
68
 
69
69
  def inspect
70
- path = [@_name]
71
- parent = @_parent
72
- until parent.nil?
73
- path << parent.instance_variable_get('@_name')
74
- parent = parent.instance_variable_get('@_parent')
75
- end
76
- path << 'configatron'
77
- path.compact!
78
- path.reverse!
70
+ name = _store_name
79
71
  f_out = []
80
72
  @_store.each do |k, v|
81
73
  if v.is_a?(Configatron::Store)
@@ -91,7 +83,7 @@ class Configatron
91
83
  end
92
84
  end
93
85
  else
94
- f_out << "#{path.join('.')}.#{k} = #{v.inspect}"
86
+ f_out << "#{name}.#{k} = #{v.inspect}"
95
87
  end
96
88
  end
97
89
  f_out.compact.sort.join("\n")
@@ -156,11 +148,11 @@ class Configatron
156
148
  raise Configatron::LockedNamespace.new(@_name) if @_locked && !@_store.has_key?(name)
157
149
  @_store[name] = parse_options(*args)
158
150
  elsif sym.to_s.match(/(.+)\?/)
159
- return !@_store[$1.to_sym].blank?
151
+ return !_store_lookup($1.to_sym).blank?
160
152
  elsif block_given?
161
153
  yield self.send(sym)
162
154
  elsif @_store.has_key?(sym)
163
- val = @_store[sym]
155
+ val = _store_lookup(sym)
164
156
  if val.is_a?(Configatron::Proc)
165
157
  res = val.execute
166
158
  if val.finalize?
@@ -170,6 +162,10 @@ class Configatron
170
162
  end
171
163
  return val
172
164
  else
165
+ # This will error out if strict is enabled, and be a no-op
166
+ # otherwise. The nice thing is the error message will be the
167
+ # same as in the .method? case.
168
+ _store_lookup(sym)
173
169
  store = Configatron::Store.new({}, sym, self)
174
170
  @_store[sym] = store
175
171
  return store
@@ -333,6 +329,30 @@ class Configatron
333
329
  end
334
330
  end
335
331
 
332
+ def _store_name
333
+ path = [@_name]
334
+ parent = @_parent
335
+ until parent.nil?
336
+ path << parent.instance_variable_get('@_name')
337
+ parent = parent.instance_variable_get('@_parent')
338
+ end
339
+ path << 'configatron'
340
+ path.compact!
341
+ path.reverse!
342
+ path.join('.')
343
+ end
344
+
345
+ # Give it this awkward name to hopefully avoid config keys people
346
+ # are using.
347
+ def _store_lookup(sym)
348
+ begin
349
+ @_store.fetch(sym)
350
+ rescue IndexError => e
351
+ raise e.class.new("#{e.message} (for #{_store_name})") if Configatron.strict
352
+ nil
353
+ end
354
+ end
355
+
336
356
  begin
337
357
  undef :test # :nodoc:
338
358
  rescue Exception => e
@@ -1,3 +1,3 @@
1
1
  class Configatron
2
- VERSION = "2.11.0"
2
+ VERSION = "2.12.0"
3
3
  end
@@ -6,6 +6,22 @@ describe "configatron" do
6
6
  configatron.reset!
7
7
  end
8
8
 
9
+ describe '.strict' do
10
+ it 'should raise an error for undefined keys' do
11
+ Configatron.strict = true
12
+ lambda {configatron.undefined}.should raise_error(IndexError)
13
+ lambda {configatron.undefined?}.should raise_error(IndexError)
14
+ end
15
+
16
+ it 'should not raise an error for existing keys' do
17
+ configatron.defined
18
+ configatron.defined?
19
+ Configatron.strict = true
20
+ configatron.defined
21
+ configatron.defined?
22
+ end
23
+ end
24
+
9
25
  it 'should respond to test without blowing up' do
10
26
  configatron.test.should be_nil
11
27
  configatron.test = 'hi!'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Bates