configurability 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +5 -0
- data/lib/configurability.rb +2 -2
- data/lib/configurability/behavior.rb +1 -1
- data/lib/configurability/config.rb +55 -53
- data/spec/configurability/config_spec.rb +16 -10
- data/spec/configurability_spec.rb +3 -3
- metadata +4 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17a4c6df3cb0a6943ed03e5dbcd4947b1cade237
|
4
|
+
data.tar.gz: fcb169f4effc4a6230ef6ce25d43687dcead2e1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb1529ea0da93d38299926bb04cf6b2d45fb7b2414147455d771e0ca11418d9107750aaaf33541c96ceec2a26930ed5ded8d77202e3a04dbd99db1aa8bff384c
|
7
|
+
data.tar.gz: 1f3b8b3a8426134c7d8dcee6ef86909d3e8c09784cfcbbaf500527d08bf4f796fd317a9fc4ae405a8b642168b1d99c2a716377d6b6f129ea53b635caf36c0e76
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
data/lib/configurability.rb
CHANGED
@@ -18,10 +18,10 @@ module Configurability
|
|
18
18
|
|
19
19
|
|
20
20
|
# Library version constant
|
21
|
-
VERSION = '2.1.
|
21
|
+
VERSION = '2.1.2'
|
22
22
|
|
23
23
|
# Version-control revision constant
|
24
|
-
REVISION = %q$Revision:
|
24
|
+
REVISION = %q$Revision: 8ccc787daf98 $
|
25
25
|
|
26
26
|
require 'configurability/deferredconfig'
|
27
27
|
|
@@ -14,7 +14,7 @@ share_examples_for "an object with Configurability" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "has a config key that is a reasonable section name" do
|
17
|
-
expect( described_class.config_key.to_s ).to match( /^[a-z]
|
17
|
+
expect( described_class.config_key.to_s ).to match( /^[a-z]\w*$/i )
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
@@ -240,7 +240,6 @@ class Configurability::Config
|
|
240
240
|
protected
|
241
241
|
#########
|
242
242
|
|
243
|
-
|
244
243
|
### Read in the specified +filename+ and return a config struct.
|
245
244
|
def make_configstruct_from_source( source, defaults=nil )
|
246
245
|
defaults ||= {}
|
@@ -251,7 +250,8 @@ class Configurability::Config
|
|
251
250
|
YAML.load( source )
|
252
251
|
end
|
253
252
|
ihash = symbolify_keys( untaint_hash(hash) )
|
254
|
-
|
253
|
+
idefaults = symbolify_keys( defaults )
|
254
|
+
mergedhash = idefaults.merge( ihash, &mergefunc )
|
255
255
|
|
256
256
|
return Configurability::Config::Struct.new( mergedhash )
|
257
257
|
end
|
@@ -277,76 +277,77 @@ class Configurability::Config
|
|
277
277
|
end
|
278
278
|
|
279
279
|
|
280
|
-
|
281
|
-
|
282
|
-
#######
|
280
|
+
# A collection of data-structure-manipulation functions.
|
281
|
+
module DataUtilities
|
283
282
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
283
|
+
### Return a copy of the specified +hash+ with all of its values
|
284
|
+
### untainted.
|
285
|
+
def untaint_hash( hash )
|
286
|
+
newhash = {}
|
287
|
+
hash.each_key do |key|
|
288
|
+
newhash[ key ] = untaint_value( hash[key] )
|
289
|
+
end
|
290
|
+
return newhash
|
290
291
|
end
|
291
|
-
return newhash
|
292
|
-
end
|
293
292
|
|
294
293
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
294
|
+
### Return an untainted copy of the specified +val+.
|
295
|
+
def untaint_value( val )
|
296
|
+
case val
|
297
|
+
when Hash
|
298
|
+
return untaint_hash( val )
|
300
299
|
|
301
|
-
|
302
|
-
|
300
|
+
when Array
|
301
|
+
return val.collect {|v| untaint_value(v) }
|
303
302
|
|
304
|
-
|
305
|
-
|
303
|
+
when NilClass, TrueClass, FalseClass, Numeric, Symbol, Encoding
|
304
|
+
return val
|
306
305
|
|
307
|
-
else
|
308
|
-
if val.respond_to?( :dup ) && val.respond_to?( :untaint )
|
309
|
-
return val.dup.untaint
|
310
306
|
else
|
311
|
-
|
307
|
+
if val.respond_to?( :dup ) && val.respond_to?( :untaint )
|
308
|
+
return val.dup.untaint
|
309
|
+
else
|
310
|
+
return val
|
311
|
+
end
|
312
312
|
end
|
313
313
|
end
|
314
|
-
end
|
315
314
|
|
316
315
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
316
|
+
### Return a duplicate of the given +hash+ with its identifier-like keys
|
317
|
+
### transformed into symbols from whatever they were before.
|
318
|
+
def symbolify_keys( hash )
|
319
|
+
newhash = {}
|
320
|
+
hash.each do |key,val|
|
321
|
+
key = key.to_sym if key.respond_to?( :to_sym )
|
323
322
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
323
|
+
if val.is_a?( Hash )
|
324
|
+
newhash[ key ] = symbolify_keys( val )
|
325
|
+
else
|
326
|
+
newhash[ key ] = val
|
327
|
+
end
|
328
328
|
end
|
329
|
-
end
|
330
329
|
|
331
|
-
|
332
|
-
|
330
|
+
return newhash
|
331
|
+
end
|
333
332
|
|
334
333
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
334
|
+
### Return a version of the given +hash+ with its keys transformed
|
335
|
+
### into Strings from whatever they were before.
|
336
|
+
def stringify_keys( hash )
|
337
|
+
newhash = {}
|
338
|
+
hash.each do |key,val|
|
339
|
+
if val.is_a?( Hash )
|
340
|
+
newhash[ key.to_s ] = stringify_keys( val )
|
341
|
+
else
|
342
|
+
newhash[ key.to_s ] = val
|
343
|
+
end
|
344
344
|
end
|
345
|
-
end
|
346
345
|
|
347
|
-
|
346
|
+
return newhash
|
347
|
+
end
|
348
348
|
end
|
349
349
|
|
350
|
+
include DataUtilities
|
350
351
|
|
351
352
|
|
352
353
|
#############################################################
|
@@ -357,7 +358,8 @@ class Configurability::Config
|
|
357
358
|
### hashes.
|
358
359
|
class Struct
|
359
360
|
extend Forwardable
|
360
|
-
include Enumerable
|
361
|
+
include Enumerable,
|
362
|
+
Configurability::Config::DataUtilities
|
361
363
|
|
362
364
|
# Mask most of Kernel's methods away so they don't collide with
|
363
365
|
# config values.
|
@@ -371,7 +373,7 @@ class Configurability::Config
|
|
371
373
|
### Create a new ConfigStruct using the values from the given +hash+ if specified.
|
372
374
|
def initialize( hash=nil )
|
373
375
|
hash ||= {}
|
374
|
-
@hash = hash
|
376
|
+
@hash = symbolify_keys( hash )
|
375
377
|
@dirty = false
|
376
378
|
end
|
377
379
|
|
@@ -74,6 +74,12 @@ describe Configurability::Config do
|
|
74
74
|
expect( config.defaultkey ).to eq( "Oh yeah." )
|
75
75
|
end
|
76
76
|
|
77
|
+
it "symbolifies keys in defaults (issue #3)" do
|
78
|
+
config = Configurability::Config.new( TEST_CONFIG, 'stringkey' => "String value." )
|
79
|
+
|
80
|
+
expect( config.stringkey ).to eq( "String value." )
|
81
|
+
end
|
82
|
+
|
77
83
|
it "yields itself if a block is given at creation" do
|
78
84
|
yielded_self = nil
|
79
85
|
config = Configurability::Config.new { yielded_self = self }
|
@@ -102,12 +108,12 @@ describe Configurability::Config do
|
|
102
108
|
it "autoloads predicates for its members" do
|
103
109
|
config = Configurability::Config.new( TEST_CONFIG )
|
104
110
|
|
105
|
-
expect( config.mergekey? ).to
|
106
|
-
expect( config.mergemonkey? ).to
|
107
|
-
expect( config.section? ).to
|
108
|
-
expect( config.section.subsection? ).to
|
109
|
-
expect( config.section.subsection.subsubsection? ).to
|
110
|
-
expect( config.section.monkeysubsection? ).to
|
111
|
+
expect( config.mergekey? ).to be_truthy()
|
112
|
+
expect( config.mergemonkey? ).to be_falsey()
|
113
|
+
expect( config.section? ).to be_truthy()
|
114
|
+
expect( config.section.subsection? ).to be_truthy()
|
115
|
+
expect( config.section.subsection.subsubsection? ).to be_truthy()
|
116
|
+
expect( config.section.monkeysubsection? ).to be_falsey()
|
111
117
|
end
|
112
118
|
|
113
119
|
it "untaints values loaded from a config" do
|
@@ -180,7 +186,7 @@ describe Configurability::Config do
|
|
180
186
|
|
181
187
|
it "returns struct members as an Array of Symbols" do
|
182
188
|
expect( config.members ).to be_an_instance_of( Array )
|
183
|
-
expect( config.members ).to
|
189
|
+
expect( config.members.size ).to be >= 4
|
184
190
|
config.members.each do |member|
|
185
191
|
expect( member ).to be_an_instance_of( Symbol )
|
186
192
|
end
|
@@ -225,7 +231,7 @@ describe Configurability::Config do
|
|
225
231
|
|
226
232
|
|
227
233
|
it "should report that it is changed" do
|
228
|
-
expect( config.changed? ).to
|
234
|
+
expect( config.changed? ).to be_truthy()
|
229
235
|
end
|
230
236
|
|
231
237
|
it "should report that its internal struct was modified as the reason for the change" do
|
@@ -301,7 +307,7 @@ describe Configurability::Config do
|
|
301
307
|
it "doesn't re-read its source file if it hasn't changed" do
|
302
308
|
expect( config.path ).not_to receive( :read )
|
303
309
|
expect( Configurability ).not_to receive( :configure_objects )
|
304
|
-
expect( config.reload ).to
|
310
|
+
expect( config.reload ).to be_falsey()
|
305
311
|
end
|
306
312
|
end
|
307
313
|
|
@@ -340,7 +346,7 @@ describe Configurability::Config do
|
|
340
346
|
it "re-reads its file when reloaded" do
|
341
347
|
expect( @config.path ).to receive( :read ).and_return( TEST_CONFIG )
|
342
348
|
expect( Configurability ).to receive( :configure_objects ).with( @config )
|
343
|
-
expect( @config.reload ).to
|
349
|
+
expect( @config.reload ).to be_truthy()
|
344
350
|
end
|
345
351
|
|
346
352
|
it "reapplies its defaults when reloading" do
|
@@ -368,9 +368,9 @@ describe Configurability do
|
|
368
368
|
expect( config ).to be_a( Configurability::Config )
|
369
369
|
expect( config.testconfig.one ).to eq( 1 )
|
370
370
|
expect( config.testconfig.two ).to eq( 2 )
|
371
|
-
expect( config.testconfig.types.one ).to
|
372
|
-
expect( config.testconfig.types.two ).to
|
373
|
-
expect( config.otherconfig.other ).to
|
371
|
+
expect( config.testconfig.types.one ).to be_truthy()
|
372
|
+
expect( config.testconfig.types.two ).to be_truthy()
|
373
|
+
expect( config.otherconfig.other ).to be_truthy()
|
374
374
|
end
|
375
375
|
|
376
376
|
it "returns defaults for an object that inherits from a class with Configurability" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
6mKCwjpegytE0oifXfF8k75A9105cBnNiMZOe1tXiqYc/exCgWvbggurzDOcRkZu
|
31
31
|
/YSusaiDXHKU2O3Akc3htA==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
33
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: loggability
|
@@ -160,6 +160,7 @@ extra_rdoc_files:
|
|
160
160
|
- Manifest.txt
|
161
161
|
- README.rdoc
|
162
162
|
files:
|
163
|
+
- .gemtest
|
163
164
|
- ChangeLog
|
164
165
|
- History.rdoc
|
165
166
|
- LICENSE
|
@@ -177,7 +178,6 @@ files:
|
|
177
178
|
- spec/configurability/deferredconfig_spec.rb
|
178
179
|
- spec/configurability_spec.rb
|
179
180
|
- spec/helpers.rb
|
180
|
-
- .gemtest
|
181
181
|
homepage: https://bitbucket.org/ged/configurability
|
182
182
|
licenses:
|
183
183
|
- BSD
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
202
|
rubyforge_project: configurability
|
203
|
-
rubygems_version: 2.1
|
203
|
+
rubygems_version: 2.2.1
|
204
204
|
signing_key:
|
205
205
|
specification_version: 4
|
206
206
|
summary: Configurability is a unified, unintrusive, assume-nothing configuration system
|
metadata.gz.sig
CHANGED
Binary file
|