configurability 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ChangeLog +101 -58
- data/History.rdoc +11 -0
- data/Manifest.txt +1 -1
- data/README.rdoc +1 -1
- data/Rakefile +3 -3
- data/lib/configurability.rb +16 -15
- data/lib/configurability/behavior.rb +3 -8
- data/lib/configurability/config.rb +1 -1
- data/spec/configurability/config_spec.rb +87 -94
- data/spec/configurability/deferredconfig_spec.rb +3 -13
- data/spec/configurability_spec.rb +121 -85
- data/spec/{lib/helpers.rb → helpers.rb} +4 -1
- metadata +30 -30
- 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: ae00303104896fbdb4479b741a713cf98447ca1a
|
4
|
+
data.tar.gz: d7aaa1d875c3f4dd0e20e152ba76ba52e62be667
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd1b469747088b887326ec6c65996e3c5485606eb20ce62556e45b407ba50b26d964fdcc6893130a7e26ae1c5981e549cff58638b1b2edb7cc709fc149574ee6
|
7
|
+
data.tar.gz: 68d3cb5b755de3e19b5ff1d910cd8f7b8ba12856627484d7d9c90da6219db3ff928aabc4250231329afa1a93367b8bfa43f84b95257e2a1afe7b983367b824b8
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/ChangeLog
CHANGED
@@ -1,8 +1,49 @@
|
|
1
|
+
2013-08-13 Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
* Rakefile, lib/configurability.rb,
|
4
|
+
spec/configurability/config_spec.rb, spec/configurability_spec.rb:
|
5
|
+
Fix behavior of inherited Configurability
|
6
|
+
[9a8961d68e99] [tip]
|
7
|
+
|
8
|
+
* lib/configurability/behavior.rb,
|
9
|
+
spec/configurability/config_spec.rb,
|
10
|
+
spec/configurability/deferredconfig_spec.rb,
|
11
|
+
spec/configurability_spec.rb, spec/helpers.rb, spec/lib/helpers.rb:
|
12
|
+
Convert specs to use expect syntax
|
13
|
+
[290c7286bd8b]
|
14
|
+
|
15
|
+
2013-06-14 Mahlon E. Smith <mahlon@martini.nu>
|
16
|
+
|
17
|
+
* .hgtags:
|
18
|
+
Added tag v2.0.2 for changeset b8b7c6673cde
|
19
|
+
[842a42780d63]
|
20
|
+
|
21
|
+
* .hgsigs:
|
22
|
+
Added signature for changeset e53b53d65079
|
23
|
+
[b8b7c6673cde] [v2.0.2]
|
24
|
+
|
25
|
+
* History.rdoc, lib/configurability.rb:
|
26
|
+
Bump to version 2.0.2.
|
27
|
+
[e53b53d65079]
|
28
|
+
|
29
|
+
* lib/configurability/config.rb:
|
30
|
+
Explicit check for safe_yaml, load YAML with default security
|
31
|
+
settings if it is installed, and silence stderr warnings.
|
32
|
+
[e33909a2e0d1]
|
33
|
+
|
1
34
|
2013-06-07 Mahlon E. Smith <mahlon@martini.nu>
|
2
35
|
|
36
|
+
* .hgtags:
|
37
|
+
Added tag v2.0.1 for changeset c25da00ba16e
|
38
|
+
[1aa2c0e1c744] [github/master]
|
39
|
+
|
40
|
+
* .hgsigs:
|
41
|
+
Added signature for changeset bbf0ba1d6deb
|
42
|
+
[c25da00ba16e] [v2.0.1]
|
43
|
+
|
3
44
|
* History.rdoc, lib/configurability.rb:
|
4
45
|
Bump version to v2.0.1.
|
5
|
-
[bbf0ba1d6deb]
|
46
|
+
[bbf0ba1d6deb]
|
6
47
|
|
7
48
|
* lib/configurability.rb:
|
8
49
|
Inject support into Loggability directly, avoiding load order
|
@@ -188,6 +229,15 @@
|
|
188
229
|
Merged with 29a1c3384b7f
|
189
230
|
[afa3d24b4117]
|
190
231
|
|
232
|
+
2012-02-06 Michael Granger <ged@FaerieMUD.org>
|
233
|
+
|
234
|
+
* lib/configurability.rb:
|
235
|
+
Make unknown config log message less chatty.
|
236
|
+
|
237
|
+
Thanks to Mahlon E. Smith for the gargantuan patch. "Ssssh baby.
|
238
|
+
It's cool. Don't say a word. There will also be corn served."
|
239
|
+
[29a1c3384b7f]
|
240
|
+
|
191
241
|
2012-01-27 Michael Granger <ged@FaerieMUD.org>
|
192
242
|
|
193
243
|
* .hgtags:
|
@@ -207,35 +257,6 @@
|
|
207
257
|
Merged with ssh://hg@bitbucket.org/ged/configurability@86718657a466
|
208
258
|
[d3f6f8d77060]
|
209
259
|
|
210
|
-
2011-11-01 Michael Granger <ged@FaerieMUD.org>
|
211
|
-
|
212
|
-
* .hgtags:
|
213
|
-
Added tag v1.0.8 for changeset 5b3d66af5a59
|
214
|
-
[86718657a466]
|
215
|
-
|
216
|
-
* .hgsigs:
|
217
|
-
Added signature for changeset 97a03db6f41c
|
218
|
-
[5b3d66af5a59] [v1.0.8]
|
219
|
-
|
220
|
-
* History.rdoc, lib/configurability.rb:
|
221
|
-
Bumped patch version and updated the History file.
|
222
|
-
[97a03db6f41c]
|
223
|
-
|
224
|
-
* spec/configurability/config_spec.rb:
|
225
|
-
Fix for Ruby 1.9.3.
|
226
|
-
[a26cd541ea8f]
|
227
|
-
|
228
|
-
2012-02-06 Michael Granger <ged@FaerieMUD.org>
|
229
|
-
|
230
|
-
* lib/configurability.rb:
|
231
|
-
Make unknown config log message less chatty.
|
232
|
-
|
233
|
-
Thanks to Mahlon E. Smith for the gargantuan patch. "Ssssh baby.
|
234
|
-
It's cool. Don't say a word. There will also be corn served."
|
235
|
-
[29a1c3384b7f]
|
236
|
-
|
237
|
-
2012-01-27 Michael Granger <ged@FaerieMUD.org>
|
238
|
-
|
239
260
|
* .hgtags:
|
240
261
|
Added tag v1.0.8 for changeset 6a7852aa7398
|
241
262
|
[5e85b9cb1122]
|
@@ -260,6 +281,24 @@
|
|
260
281
|
Adding TextMate properties
|
261
282
|
[45b92add3e1e]
|
262
283
|
|
284
|
+
2011-11-01 Michael Granger <ged@FaerieMUD.org>
|
285
|
+
|
286
|
+
* .hgtags:
|
287
|
+
Added tag v1.0.8 for changeset 5b3d66af5a59
|
288
|
+
[86718657a466]
|
289
|
+
|
290
|
+
* .hgsigs:
|
291
|
+
Added signature for changeset 97a03db6f41c
|
292
|
+
[5b3d66af5a59] [v1.0.8]
|
293
|
+
|
294
|
+
* History.rdoc, lib/configurability.rb:
|
295
|
+
Bumped patch version and updated the History file.
|
296
|
+
[97a03db6f41c]
|
297
|
+
|
298
|
+
* spec/configurability/config_spec.rb:
|
299
|
+
Fix for Ruby 1.9.3.
|
300
|
+
[a26cd541ea8f]
|
301
|
+
|
263
302
|
2011-10-13 Michael Granger <ged@FaerieMUD.org>
|
264
303
|
|
265
304
|
* .hgtags:
|
@@ -344,24 +383,6 @@
|
|
344
383
|
Removed tag v1.0.4
|
345
384
|
[1ef1012b278c]
|
346
385
|
|
347
|
-
* .hgtags:
|
348
|
-
Added tag v1.0.4 for changeset 84718f122b7b
|
349
|
-
[99d382b750f6]
|
350
|
-
|
351
|
-
* .hgsigs:
|
352
|
-
Added signature for changeset eef299ea1d29
|
353
|
-
[84718f122b7b]
|
354
|
-
|
355
|
-
* lib/configurability.rb, lib/configurability/config.rb,
|
356
|
-
spec/configurability/config_spec.rb:
|
357
|
-
Fix for config files with nil keys (fixes #1)
|
358
|
-
[eef299ea1d29]
|
359
|
-
|
360
|
-
* .hgsub, .hgsubstate, .hgsubstate, History.md, LICENSE, Manifest.txt,
|
361
|
-
README.md, Rakefile, project.yml:
|
362
|
-
Converted to Hoe.
|
363
|
-
[fb024df77138]
|
364
|
-
|
365
386
|
2010-11-29 Michael Granger <ged@FaerieMUD.org>
|
366
387
|
|
367
388
|
* .hgsub:
|
@@ -384,6 +405,28 @@
|
|
384
405
|
Adding Github mirror to the README
|
385
406
|
[bb8f2829eb37]
|
386
407
|
|
408
|
+
2011-02-08 Michael Granger <ged@FaerieMUD.org>
|
409
|
+
|
410
|
+
* .hgtags:
|
411
|
+
Added tag v1.0.4 for changeset 84718f122b7b
|
412
|
+
[99d382b750f6]
|
413
|
+
|
414
|
+
* .hgsigs:
|
415
|
+
Added signature for changeset eef299ea1d29
|
416
|
+
[84718f122b7b]
|
417
|
+
|
418
|
+
* lib/configurability.rb, lib/configurability/config.rb,
|
419
|
+
spec/configurability/config_spec.rb:
|
420
|
+
Fix for config files with nil keys (fixes #1)
|
421
|
+
[eef299ea1d29]
|
422
|
+
|
423
|
+
* .hgsub, .hgsubstate, .hgsubstate, History.md, LICENSE, Manifest.txt,
|
424
|
+
README.md, Rakefile, project.yml:
|
425
|
+
Converted to Hoe.
|
426
|
+
[fb024df77138]
|
427
|
+
|
428
|
+
2010-11-29 Michael Granger <ged@FaerieMUD.org>
|
429
|
+
|
387
430
|
* .hgtags:
|
388
431
|
Added tag v1.0.3 for changeset 910ae8ac082f
|
389
432
|
[a2ae16f86c98]
|
@@ -425,6 +468,16 @@
|
|
425
468
|
* Merged with 17:e2bf2e43bccf
|
426
469
|
[17a6999c08b9]
|
427
470
|
|
471
|
+
2010-08-08 Michael Granger <ged@FaerieMUD.org>
|
472
|
+
|
473
|
+
* .hgtags:
|
474
|
+
Added tag 1.0.1 for changeset e3605ccbe057
|
475
|
+
[4bff6d5f7b6e]
|
476
|
+
|
477
|
+
* .hgsigs:
|
478
|
+
Added signature for changeset 41bc1de0bf36
|
479
|
+
[e3605ccbe057] [1.0.1]
|
480
|
+
|
428
481
|
2010-10-25 Michael Granger <ged@FaerieMUD.org>
|
429
482
|
|
430
483
|
* lib/configurability/behavior.rb:
|
@@ -437,16 +490,6 @@
|
|
437
490
|
Converted tests to RSpec 2.
|
438
491
|
[5d18e28e387b]
|
439
492
|
|
440
|
-
2010-08-08 Michael Granger <ged@FaerieMUD.org>
|
441
|
-
|
442
|
-
* .hgtags:
|
443
|
-
Added tag 1.0.1 for changeset e3605ccbe057
|
444
|
-
[4bff6d5f7b6e]
|
445
|
-
|
446
|
-
* .hgsigs:
|
447
|
-
Added signature for changeset 41bc1de0bf36
|
448
|
-
[e3605ccbe057] [1.0.1]
|
449
|
-
|
450
493
|
2010-08-04 Michael Granger <ged@FaerieMUD.org>
|
451
494
|
|
452
495
|
* .hgignore, README.md, lib/configurability/config.rb,
|
data/History.rdoc
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== v2.1.0 [2013-08-13] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
- Fix behavior of inherited Configurability
|
4
|
+
- Convert specs to use RSpec expect syntax
|
5
|
+
- Drop support for Ruby 1.8.7.
|
6
|
+
|
7
|
+
|
8
|
+
== v2.0.2 [2013-06-14] Mahlon E. Smith <mahlon@martini.nu>
|
9
|
+
|
10
|
+
- Added signature for changeset e53b53d65079
|
11
|
+
|
1
12
|
== v2.0.2 [2013-06-14] Mahlon E. Smith <mahlon@martini.nu>
|
2
13
|
|
3
14
|
- Load YAML safely if the safe_yaml gem is present.
|
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -24,12 +24,12 @@ hoespec = Hoe.spec 'configurability' do
|
|
24
24
|
|
25
25
|
self.dependency 'loggability', '~> 0.4'
|
26
26
|
|
27
|
-
self.dependency 'rspec', '~> 2.
|
28
|
-
self.dependency 'simplecov', '~> 0.
|
27
|
+
self.dependency 'rspec', '~> 2.14', :developer
|
28
|
+
self.dependency 'simplecov', '~> 0.5', :developer
|
29
29
|
|
30
30
|
self.spec_extras[:licenses] = ["BSD"]
|
31
31
|
self.spec_extras[:rdoc_options] = ['-f', 'fivefish', '-t', 'Configurability Toolkit']
|
32
|
-
self.require_ruby_version( '>= 1.
|
32
|
+
self.require_ruby_version( '>= 1.9.2' )
|
33
33
|
|
34
34
|
self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
|
35
35
|
self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
|
data/lib/configurability.rb
CHANGED
@@ -18,10 +18,10 @@ module Configurability
|
|
18
18
|
|
19
19
|
|
20
20
|
# Library version constant
|
21
|
-
VERSION = '2.0
|
21
|
+
VERSION = '2.1.0'
|
22
22
|
|
23
23
|
# Version-control revision constant
|
24
|
-
REVISION = %q$Revision:
|
24
|
+
REVISION = %q$Revision: d27195f9c3df $
|
25
25
|
|
26
26
|
require 'configurability/deferredconfig'
|
27
27
|
|
@@ -99,10 +99,10 @@ module Configurability
|
|
99
99
|
end
|
100
100
|
|
101
101
|
|
102
|
-
### Configure objects that have had Configurability added to them with
|
103
|
-
### the sections of the specified +config+ that correspond to their
|
102
|
+
### Configure objects that have had Configurability added to them with
|
103
|
+
### the sections of the specified +config+ that correspond to their
|
104
104
|
### +config_key+. If the +config+ doesn't #respond_to the object's
|
105
|
-
### +config_key+, the object's #configure method is called with +nil+
|
105
|
+
### +config_key+, the object's #configure method is called with +nil+
|
106
106
|
### instead.
|
107
107
|
def self::configure_objects( config )
|
108
108
|
self.log.debug "Splitting up config %p between %d objects with configurability." %
|
@@ -170,13 +170,13 @@ module Configurability
|
|
170
170
|
def self::gather_defaults( collection={} )
|
171
171
|
self.configurable_objects.each do |obj|
|
172
172
|
next unless obj.respond_to?( :defaults )
|
173
|
-
|
173
|
+
if subhash = obj.defaults
|
174
|
+
section = obj.config_key.to_sym
|
175
|
+
Configurability.log.debug "Defaults for %p (%p): %p" % [ obj, section, subhash ]
|
176
|
+
collection.merge!( section => subhash )
|
177
|
+
else
|
174
178
|
Configurability.log.warn "No defaults for %p; skipping" % [ obj ]
|
175
|
-
next
|
176
179
|
end
|
177
|
-
section = obj.config_key.to_sym
|
178
|
-
|
179
|
-
collection.merge!( section => subhash )
|
180
180
|
end
|
181
181
|
|
182
182
|
return collection
|
@@ -199,7 +199,7 @@ module Configurability
|
|
199
199
|
|
200
200
|
### Get (and optionally set) the +config_key+ (a Symbol).
|
201
201
|
def config_key( sym=nil )
|
202
|
-
|
202
|
+
self.config_key = sym unless sym.nil?
|
203
203
|
@config_key ||= Configurability.make_key_from_object( self )
|
204
204
|
@config_key
|
205
205
|
end
|
@@ -207,6 +207,7 @@ module Configurability
|
|
207
207
|
|
208
208
|
### Set the config key of the object.
|
209
209
|
def config_key=( sym )
|
210
|
+
Configurability.configurable_objects |= [ self ]
|
210
211
|
@config_key = sym
|
211
212
|
end
|
212
213
|
|
@@ -230,12 +231,12 @@ module Configurability
|
|
230
231
|
return nil unless respond_to?( :const_defined? )
|
231
232
|
|
232
233
|
Configurability.log.debug "Looking for defaults in %p's constants." % [ self ]
|
233
|
-
if self.const_defined?( :DEFAULT_CONFIG )
|
234
|
+
if self.const_defined?( :DEFAULT_CONFIG, false )
|
234
235
|
Configurability.log.debug " found DEFAULT_CONFIG"
|
235
|
-
return self.const_get( :DEFAULT_CONFIG ).dup
|
236
|
-
elsif self.const_defined?( :CONFIG_DEFAULTS )
|
236
|
+
return self.const_get( :DEFAULT_CONFIG, false ).dup
|
237
|
+
elsif self.const_defined?( :CONFIG_DEFAULTS, false )
|
237
238
|
Configurability.log.debug " found CONFIG_DEFAULTS"
|
238
|
-
return self.const_get( :CONFIG_DEFAULTS ).dup
|
239
|
+
return self.const_get( :CONFIG_DEFAULTS, false ).dup
|
239
240
|
else
|
240
241
|
Configurability.log.debug " no default constants."
|
241
242
|
return nil
|
@@ -5,21 +5,16 @@ require 'rspec'
|
|
5
5
|
|
6
6
|
share_examples_for "an object with Configurability" do
|
7
7
|
|
8
|
-
let( :config ) do
|
9
|
-
described_class
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
8
|
it "is extended with Configurability" do
|
14
|
-
Configurability.configurable_objects.
|
9
|
+
expect( Configurability.configurable_objects ).to include( described_class )
|
15
10
|
end
|
16
11
|
|
17
12
|
it "has a Symbol config key" do
|
18
|
-
|
13
|
+
expect( described_class.config_key ).to be_a( Symbol )
|
19
14
|
end
|
20
15
|
|
21
16
|
it "has a config key that is a reasonable section name" do
|
22
|
-
|
17
|
+
expect( described_class.config_key.to_s ).to match( /^[a-z][a-z0-9]*$/i )
|
23
18
|
end
|
24
19
|
|
25
20
|
end
|
@@ -1,21 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
6
|
-
|
7
|
-
libdir = basedir + "lib"
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
11
|
-
}
|
3
|
+
require 'helpers'
|
12
4
|
|
13
5
|
require 'logger'
|
14
6
|
require 'fileutils'
|
15
7
|
require 'rspec'
|
16
8
|
|
17
|
-
require 'spec/lib/helpers'
|
18
|
-
|
19
9
|
require 'configurability/config'
|
20
10
|
|
21
11
|
|
@@ -56,11 +46,11 @@ describe Configurability::Config do
|
|
56
46
|
end
|
57
47
|
|
58
48
|
it "can dump itself as YAML" do
|
59
|
-
Configurability::Config.new.dump.strip.
|
49
|
+
expect( Configurability::Config.new.dump.strip ).to eq( "--- {}" )
|
60
50
|
end
|
61
51
|
|
62
52
|
it "returns nil as its change description" do
|
63
|
-
Configurability::Config.new.changed_reason.
|
53
|
+
expect( Configurability::Config.new.changed_reason ).to be_nil()
|
64
54
|
end
|
65
55
|
|
66
56
|
it "autogenerates accessors for non-existant struct members" do
|
@@ -68,18 +58,21 @@ describe Configurability::Config do
|
|
68
58
|
config.plugins ||= {}
|
69
59
|
config.plugins.filestore ||= {}
|
70
60
|
config.plugins.filestore.maxsize = 1024
|
71
|
-
|
61
|
+
|
62
|
+
expect( config.plugins.filestore.maxsize ).to eq( 1024 )
|
72
63
|
end
|
73
64
|
|
74
65
|
it "merges values loaded from the config with any defaults given" do
|
75
66
|
config = Configurability::Config.new( TEST_CONFIG, :defaultkey => "Oh yeah." )
|
76
|
-
|
67
|
+
|
68
|
+
expect( config.defaultkey ).to eq( "Oh yeah." )
|
77
69
|
end
|
78
70
|
|
79
71
|
it "yields itself if a block is given at creation" do
|
80
72
|
yielded_self = nil
|
81
73
|
config = Configurability::Config.new { yielded_self = self }
|
82
|
-
|
74
|
+
|
75
|
+
expect( yielded_self ).to equal( config )
|
83
76
|
end
|
84
77
|
|
85
78
|
it "passes itself as the block argument if a block of arity 1 is given at creation" do
|
@@ -89,23 +82,26 @@ describe Configurability::Config do
|
|
89
82
|
yielded_self = self
|
90
83
|
arg_self = arg
|
91
84
|
end
|
92
|
-
|
93
|
-
|
85
|
+
|
86
|
+
expect( yielded_self ).not_to equal( config )
|
87
|
+
expect( arg_self ).to equal( config )
|
94
88
|
end
|
95
89
|
|
96
90
|
it "supports both Symbols and Strings for Hash-like access" do
|
97
91
|
config = Configurability::Config.new( TEST_CONFIG )
|
98
|
-
|
92
|
+
|
93
|
+
expect( config[:section]['subsection'][:subsubsection] ).to eq( 'value' )
|
99
94
|
end
|
100
95
|
|
101
96
|
it "autoloads predicates for its members" do
|
102
97
|
config = Configurability::Config.new( TEST_CONFIG )
|
103
|
-
|
104
|
-
config.
|
105
|
-
config.
|
106
|
-
config.section.
|
107
|
-
config.section.subsection.
|
108
|
-
config.section.
|
98
|
+
|
99
|
+
expect( config.mergekey? ).to be_true()
|
100
|
+
expect( config.mergemonkey? ).to be_false()
|
101
|
+
expect( config.section? ).to be_true()
|
102
|
+
expect( config.section.subsection? ).to be_true()
|
103
|
+
expect( config.section.subsection.subsubsection? ).to be_true()
|
104
|
+
expect( config.section.monkeysubsection? ).to be_false()
|
109
105
|
end
|
110
106
|
|
111
107
|
|
@@ -122,17 +118,16 @@ describe Configurability::Config do
|
|
122
118
|
- pattern2
|
123
119
|
}.gsub(/^\t{2}/, '')
|
124
120
|
|
125
|
-
|
126
|
-
@config = Configurability::Config.new( NIL_KEY_CONFIG )
|
127
|
-
end
|
121
|
+
let( :config ) { Configurability::Config.new(NIL_KEY_CONFIG) }
|
128
122
|
|
129
123
|
it "doesn't raise a NoMethodError when loading (issue #1)" do
|
130
|
-
|
131
|
-
|
124
|
+
val = config[:trap_on]['low disk space alert'][nil][:notepad][:patterns]
|
125
|
+
expect( val ).to eq([ 'pattern1', 'pattern2' ])
|
132
126
|
end
|
133
127
|
|
134
128
|
it "knows that it has a nil member" do
|
135
|
-
|
129
|
+
val = config[:trap_on]['low disk space alert']
|
130
|
+
expect( val ).to have_member( nil )
|
136
131
|
end
|
137
132
|
|
138
133
|
end
|
@@ -140,69 +135,67 @@ describe Configurability::Config do
|
|
140
135
|
|
141
136
|
context "created with in-memory YAML source" do
|
142
137
|
|
143
|
-
|
144
|
-
@config = Configurability::Config.new( TEST_CONFIG )
|
145
|
-
end
|
138
|
+
let( :config ) { Configurability::Config.new(TEST_CONFIG) }
|
146
139
|
|
147
140
|
it "responds to methods which are the same as struct members" do
|
148
|
-
|
149
|
-
|
150
|
-
|
141
|
+
expect( config ).to respond_to( :section )
|
142
|
+
expect( config.section ).to respond_to( :subsection )
|
143
|
+
expect( config ).not_to respond_to( :pork_sausage )
|
151
144
|
end
|
152
145
|
|
153
146
|
it "contains values specified in the source" do
|
154
147
|
# section:
|
155
148
|
# subsection:
|
156
149
|
# subsubsection: value
|
157
|
-
|
150
|
+
expect( config.section.subsection.subsubsection ).to eq( 'value' )
|
158
151
|
|
159
152
|
# listsection:
|
160
153
|
# - list
|
161
154
|
# - values
|
162
155
|
# - are
|
163
156
|
# - neat
|
164
|
-
|
157
|
+
expect( config.listsection ).to eq( %w[list values are neat] )
|
165
158
|
|
166
159
|
# mergekey: Yep.
|
167
|
-
|
160
|
+
expect( config.mergekey ).to eq( 'Yep.' )
|
168
161
|
|
169
162
|
# textsection: |-
|
170
163
|
# With some text as the value
|
171
164
|
# ...and another line.
|
172
|
-
|
165
|
+
expect( config.textsection ).to eq("With some text as the value\n...and another line.")
|
173
166
|
end
|
174
167
|
|
175
168
|
it "returns struct members as an Array of Symbols" do
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
member.
|
169
|
+
expect( config.members ).to be_an_instance_of( Array )
|
170
|
+
expect( config.members ).to have_at_least( 4 ).things
|
171
|
+
config.members.each do |member|
|
172
|
+
expect( member ).to be_an_instance_of( Symbol )
|
180
173
|
end
|
181
174
|
end
|
182
175
|
|
183
176
|
it "is able to iterate over sections" do
|
184
|
-
|
185
|
-
key.
|
177
|
+
config.each do |key, struct|
|
178
|
+
expect( key ).to be_an_instance_of( Symbol )
|
186
179
|
end
|
187
180
|
end
|
188
181
|
|
189
182
|
it "dumps values specified in the source" do
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
183
|
+
expect( config.dump ).to match( /^section:/ )
|
184
|
+
expect( config.dump ).to match( /^\s+subsection:/ )
|
185
|
+
expect( config.dump ).to match( /^\s+subsubsection:/ )
|
186
|
+
expect( config.dump ).to match( /^- list/ )
|
194
187
|
end
|
195
188
|
|
196
189
|
it "provides a human-readable description of itself when inspected" do
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
190
|
+
expect( config.inspect ).to match( /4 sections/i )
|
191
|
+
expect( config.inspect ).to match( /mergekey/ )
|
192
|
+
expect( config.inspect ).to match( /textsection/ )
|
193
|
+
expect( config.inspect ).to match( /from memory/i )
|
201
194
|
end
|
202
195
|
|
203
196
|
it "raises an exception when reloaded" do
|
204
197
|
expect {
|
205
|
-
|
198
|
+
config.reload
|
206
199
|
}.to raise_exception( RuntimeError, /can't reload from an in-memory source/i )
|
207
200
|
end
|
208
201
|
|
@@ -211,19 +204,19 @@ describe Configurability::Config do
|
|
211
204
|
|
212
205
|
# saving if changed since loaded
|
213
206
|
context " whose internal values have been changed since loaded" do
|
214
|
-
|
215
|
-
|
216
|
-
|
207
|
+
let( :config ) do
|
208
|
+
config = Configurability::Config.new( TEST_CONFIG )
|
209
|
+
config.section.subsection.anothersection = 11451
|
210
|
+
config
|
217
211
|
end
|
218
212
|
|
219
213
|
|
220
|
-
### Specifications
|
221
214
|
it "should report that it is changed" do
|
222
|
-
|
215
|
+
expect( config.changed? ).to be_true()
|
223
216
|
end
|
224
217
|
|
225
218
|
it "should report that its internal struct was modified as the reason for the change" do
|
226
|
-
|
219
|
+
expect( config.changed_reason ).to match( /struct was modified/i )
|
227
220
|
end
|
228
221
|
|
229
222
|
end
|
@@ -241,35 +234,35 @@ describe Configurability::Config do
|
|
241
234
|
@tmpfile.unlink
|
242
235
|
end
|
243
236
|
|
244
|
-
|
245
|
-
@config = Configurability::Config.load( @tmpfile.to_s )
|
246
|
-
end
|
237
|
+
let( :config ) { Configurability::Config.load(@tmpfile.to_s) }
|
247
238
|
|
248
239
|
|
249
240
|
### Specifications
|
250
241
|
it "remembers which file it was loaded from" do
|
251
|
-
|
242
|
+
expect( config.path ).to eq( @tmpfile.expand_path )
|
252
243
|
end
|
253
244
|
|
254
245
|
it "writes itself back to the same file by default" do
|
255
|
-
|
256
|
-
|
246
|
+
config.port = 114411
|
247
|
+
config.write
|
257
248
|
otherconfig = Configurability::Config.load( @tmpfile.to_s )
|
258
249
|
|
259
|
-
otherconfig.port.
|
250
|
+
expect( otherconfig.port ).to eq( 114411 )
|
260
251
|
end
|
261
252
|
|
262
253
|
it "can be written to a different file" do
|
254
|
+
begin
|
263
255
|
path = Dir::Tmpname.make_tmpname( './another-', '.config' )
|
264
256
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
257
|
+
config.write( path )
|
258
|
+
expect( File.read(path) ).to match( /section: ?\n subsection/ )
|
259
|
+
ensure
|
260
|
+
File.unlink( path ) if path
|
261
|
+
end
|
269
262
|
end
|
270
263
|
|
271
264
|
it "includes the name of the file in its inspect output" do
|
272
|
-
|
265
|
+
expect( config.inspect ).to include( File.basename(@tmpfile.to_s) )
|
273
266
|
end
|
274
267
|
|
275
268
|
it "yields itself if a block is given at load-time" do
|
@@ -277,7 +270,7 @@ describe Configurability::Config do
|
|
277
270
|
config = Configurability::Config.load( @tmpfile.to_s ) do
|
278
271
|
yielded_self = self
|
279
272
|
end
|
280
|
-
yielded_self.
|
273
|
+
expect( yielded_self ).to equal( config )
|
281
274
|
end
|
282
275
|
|
283
276
|
it "passes itself as the block argument if a block of arity 1 is given at load-time" do
|
@@ -287,14 +280,15 @@ describe Configurability::Config do
|
|
287
280
|
yielded_self = self
|
288
281
|
arg_self = arg
|
289
282
|
end
|
290
|
-
|
291
|
-
|
283
|
+
|
284
|
+
expect( yielded_self ).not_to equal( config )
|
285
|
+
expect( arg_self ).to equal( config )
|
292
286
|
end
|
293
287
|
|
294
288
|
it "doesn't re-read its source file if it hasn't changed" do
|
295
|
-
|
296
|
-
Configurability.
|
297
|
-
|
289
|
+
expect( config.path ).not_to receive( :read )
|
290
|
+
expect( Configurability ).not_to receive( :configure_objects )
|
291
|
+
expect( config.reload ).to be_false()
|
298
292
|
end
|
299
293
|
end
|
300
294
|
|
@@ -323,39 +317,38 @@ describe Configurability::Config do
|
|
323
317
|
|
324
318
|
### Specifications
|
325
319
|
it "reports that it is changed" do
|
326
|
-
@config.
|
320
|
+
expect( @config ).to be_changed
|
327
321
|
end
|
328
322
|
|
329
323
|
it "reports that its source was updated as the reason for the change" do
|
330
|
-
@config.changed_reason.
|
324
|
+
expect( @config.changed_reason ).to match( /source.*updated/i )
|
331
325
|
end
|
332
326
|
|
333
327
|
it "re-reads its file when reloaded" do
|
334
|
-
@config.path.
|
335
|
-
Configurability.
|
336
|
-
@config.reload.
|
328
|
+
expect( @config.path ).to receive( :read ).and_return( TEST_CONFIG )
|
329
|
+
expect( Configurability ).to receive( :configure_objects ).with( @config )
|
330
|
+
expect( @config.reload ).to be_true()
|
337
331
|
end
|
338
332
|
|
339
333
|
it "reapplies its defaults when reloading" do
|
340
|
-
config = Configurability::Config.load( @tmpfile.to_s, :defaultskey => 8 )
|
341
|
-
config.reload
|
342
|
-
|
334
|
+
@config = Configurability::Config.load( @tmpfile.to_s, :defaultskey => 8 )
|
335
|
+
@config.reload
|
336
|
+
|
337
|
+
expect( @config.defaultskey ).to eq( 8 )
|
343
338
|
end
|
344
339
|
end
|
345
340
|
|
346
341
|
|
347
342
|
# merging
|
348
343
|
context " created by merging two other configs" do
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
@merged = @config1.merge( @config2 )
|
353
|
-
end
|
344
|
+
let( :config1 ) { Configurability::Config.new }
|
345
|
+
let( :config2 ) { Configurability::Config.new(TEST_CONFIG) }
|
346
|
+
let( :merged ) { config1.merge(config2) }
|
354
347
|
|
355
348
|
|
356
349
|
### Specifications
|
357
350
|
it "should contain values from both" do
|
358
|
-
|
351
|
+
expect( merged.mergekey ).to eq( config2.mergekey )
|
359
352
|
end
|
360
353
|
end
|
361
354
|
|