iqeo-conf 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iqeo-conf (0.0.4)
4
+ iqeo-conf (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -98,8 +98,7 @@ Need time (have motivation)...
98
98
  * Load configurations from a string or file after creation / in DSL block
99
99
  * Option to get hash directly to prevent polluting namespace with delegated hash methods
100
100
  * Blank slate for DSL ? - optional ?
101
- * Global configuration - watch for collisions ?
102
- * Issues around deferred interpolation / procs / lambdas etc...
101
+ * Consider issues around deferred interpolation / procs / lambdas etc...
103
102
  * Load other formats into configuration - YAML, CSV, ...anything Enumerable should be easy enough.
104
103
 
105
104
  ## License
@@ -1,5 +1,5 @@
1
1
  module Iqeo
2
2
  class Configuration
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -2,15 +2,15 @@
2
2
  require_relative "configuration/version"
3
3
  require_relative "configuration/hash_with_indifferent_access"
4
4
 
5
+ # fix: nested configurations broken for DSL !!
6
+ # todo: clean DSL syntax for creating a configuration - just a block ?
5
7
  # todo: configuration file load path - array of Dir.glob like file specs ?
6
8
  # todo: use an existing configuration for defaults
7
- # todo: clean DSL syntax for creating a configuration - just a block ?
8
9
  # todo: load configurations from a string or file after creation / in DSL block
9
10
  # todo: option to get hash directly to prevent polluting namespace with delegated hash methods
10
11
  # todo: blank slate for DSL - optional ?
11
- # todo: global configuration - watch for collisions ?
12
- # todo: deferred interpolation / procs / lambdas etc...
13
- # todo: load other formats from string & file - YAML, XML?
12
+ # todo: consider issues around deferred interpolation / procs / lambdas etc...
13
+ # todo: load other formats from string & file - YAML, CSV, ...anything Enumerable should be easy enough.
14
14
 
15
15
  module Iqeo
16
16
 
@@ -42,8 +42,8 @@ module Iqeo
42
42
  end
43
43
  end
44
44
 
45
- def method_missing name, *values
46
- return @items.send name, *values if @items.respond_to? name
45
+ def method_missing name, *values, &block
46
+ return @items.send name, *values if @items.respond_to? name # @items methods are highest priority
47
47
  # this is unreachable since these methods are delegated to @items hash
48
48
  # but keep it around for when we make selective delegation an option
49
49
  #case name
@@ -51,9 +51,10 @@ module Iqeo
51
51
  #when :[] then return _get values.shift
52
52
  #end
53
53
  name = name.to_s.chomp('=') # todo: write a test case for a non-string object as key being converted by .to_s
54
- return _get name if values.empty?
55
- return _set name, values if values.size > 1
56
- return _set name, values.first
54
+ return _set name, Configuration.new( &block ) if block_given? # block is a nested configuration
55
+ return _get name if values.empty? # just get item
56
+ return _set name, values if values.size > 1 # set item to multiple values
57
+ return _set name, values.first # set item to single value
57
58
  end
58
59
 
59
60
  attr_accessor :_parent # todo: should attr_writer be protected ?
Binary file
@@ -36,7 +36,7 @@ describe Configuration do
36
36
  conf_new.should be conf_yielded
37
37
  end
38
38
 
39
- end
39
+ end # creation
40
40
 
41
41
  context 'settings retrieval' do
42
42
 
@@ -45,7 +45,7 @@ describe Configuration do
45
45
  conf.not_a_setting.should be_nil
46
46
  end
47
47
 
48
- end
48
+ end # settings retrieval
49
49
 
50
50
  context 'single value setting' do
51
51
 
@@ -81,7 +81,7 @@ describe Configuration do
81
81
  conf.bravo[:c].should == 3
82
82
  end
83
83
 
84
- end
84
+ end # single value setting
85
85
 
86
86
  context 'multiple value setting' do
87
87
 
@@ -107,7 +107,7 @@ describe Configuration do
107
107
  conf.alpha.should == [ 1, 2, 3, { 'a' => 4, 'b' => 5, 'c' => 6} ] and conf.alpha.should be_a Array
108
108
  end
109
109
 
110
- end
110
+ end # multiple value setting
111
111
 
112
112
  context 'hash operators [] & []= access' do
113
113
 
@@ -130,7 +130,7 @@ describe Configuration do
130
130
  conf['alpha'].should == 1
131
131
  end
132
132
 
133
- end
133
+ end # hash operators [] & []= access
134
134
 
135
135
  context 'nested configuration' do
136
136
 
@@ -208,120 +208,279 @@ describe Configuration do
208
208
  conf.alpha.bravo.level.should == 3
209
209
  end
210
210
 
211
- end
212
-
213
- context 'yield DSL' do
214
-
215
- it 'accepts settings without =' do
216
- conf = nil
217
- expect do
218
- conf = Configuration.new do |c|
219
- c.alpha :value
220
- end
221
- end.to_not raise_error
222
- conf.should_not be_nil
223
- conf.alpha.should == :value
224
- end
225
-
226
- it 'accepts settings with =' do
227
- conf = nil
228
- expect do
229
- conf = Configuration.new do |c|
230
- c.alpha = :value
231
- end
232
- end.to_not raise_error
233
- conf.should_not be_nil
234
- conf.alpha.should == :value
235
- end
236
-
237
- it 'can refer to an existing setting' do
238
- conf = nil
239
- expect do
240
- conf = Configuration.new do |c|
241
- c.alpha = :value
242
- c.bravo = c.alpha
243
- c.charlie c.bravo
244
- end
245
- end.to_not raise_error
246
- conf.should_not be_nil
247
- conf.alpha.should == :value
248
- conf.bravo.should == :value
249
- conf.charlie.should == :value
250
- end
251
-
252
- it 'returns value when creating/changing a setting' do
253
- conf = nil
254
- expect do
255
- conf = Configuration.new do |c|
256
- c.bravo = c.alpha = :value
257
- end
258
- end.to_not raise_error
259
- conf.alpha.should == :value
260
- conf.bravo.should == :value
261
- end
262
-
263
- end
264
-
265
- context 'instance_eval DSL' do
266
-
267
- it 'accepts settings without =' do
268
- conf = nil
269
- expect do
270
- conf = Configuration.new do
271
- alpha :value
272
- end
273
- end.to_not raise_error
274
- conf.should_not be_nil
275
- conf.alpha.should == :value
276
- end
277
-
278
- it 'sets local variables with =' do
279
- conf = alpha = nil
280
- expect do
281
- alpha = nil
282
- conf = Configuration.new do
283
- alpha = :value
284
- bravo alpha
285
- end
286
- end.to_not raise_error
287
- conf.should_not be_nil
288
- conf.alpha.should be_nil
289
- conf.bravo.should == :value
290
- alpha.should == :value # local alpha set by matching variables
291
- end
292
-
293
- it 'can refer to an existing setting' do
294
- conf = nil
295
- expect do
296
- conf = Configuration.new do |c|
297
- c.alpha :value
298
- c.bravo c.alpha
299
- c.charlie c.bravo
300
- end
301
- end.to_not raise_error
302
- conf.should_not be_nil
303
- conf.alpha.should == :value
304
- conf.bravo.should == :value
305
- conf.charlie.should == :value
306
- end
307
-
308
- it 'returns value when creating/changing a setting' do
309
- conf = nil
310
- expect do
311
- conf = Configuration.new do
312
- bravo alpha :value
313
- end
314
- end.to_not raise_error
315
- conf.alpha.should == :value
316
- conf.bravo.should == :value
317
- end
318
-
319
- end
211
+ end # nested configuration
212
+
213
+ context 'mode of usage' do
214
+
215
+ context 'explicit' do
216
+
217
+ it 'accepts settings without =' do
218
+ conf = nil
219
+ expect do
220
+ conf = Configuration.new
221
+ conf.alpha :value
222
+ end.to_not raise_error
223
+ conf.should_not be_nil
224
+ conf.alpha.should == :value
225
+ end
226
+
227
+ it 'accepts settings with =' do
228
+ conf = nil
229
+ expect do
230
+ conf = Configuration.new
231
+ conf.alpha = :value
232
+ end.to_not raise_error
233
+ conf.should_not be_nil
234
+ conf.alpha.should == :value
235
+ end
236
+
237
+ it 'can refer to an existing setting' do
238
+ conf = nil
239
+ expect do
240
+ conf = Configuration.new
241
+ conf.alpha = :value
242
+ conf.bravo = conf.alpha
243
+ conf.charlie conf.bravo
244
+ end.to_not raise_error
245
+ conf.should_not be_nil
246
+ conf.alpha.should == :value
247
+ conf.bravo.should == :value
248
+ conf.charlie.should == :value
249
+ end
250
+
251
+ it 'returns value when creating/changing a setting' do
252
+ conf = nil
253
+ expect do
254
+ conf = Configuration.new
255
+ conf.bravo = conf.alpha = :value
256
+ end.to_not raise_error
257
+ conf.should_not be_nil
258
+ conf.alpha.should == :value
259
+ conf.bravo.should == :value
260
+ end
261
+
262
+ it 'supports nested configuration via Configuration.new' do
263
+ conf = nil
264
+ expect do
265
+ conf = Configuration.new
266
+ conf.alpha true
267
+ conf.bravo Configuration.new
268
+ conf.bravo.charlie true
269
+ conf.bravo.delta Configuration.new
270
+ conf.bravo.delta.echo true
271
+ end.to_not raise_error
272
+ conf.should_not be_nil
273
+ conf.alpha.should be_true
274
+ conf.bravo.should be_a Configuration
275
+ conf.bravo.alpha should be_true
276
+ conf.bravo.charlie should be_true
277
+ conf.bravo.delta.should be_a Configuration
278
+ conf.bravo.delta.alpha.should be_true
279
+ conf.bravo.delta.charlie.should be_true
280
+ conf.bravo.delta.echo.should be_true
281
+ end
282
+
283
+ end # explicit
284
+
285
+ context 'yield DSL' do
286
+
287
+ it 'accepts settings without =' do
288
+ conf = nil
289
+ expect do
290
+ conf = Configuration.new do |c|
291
+ c.alpha :value
292
+ end
293
+ end.to_not raise_error
294
+ conf.should_not be_nil
295
+ conf.alpha.should == :value
296
+ end
297
+
298
+ it 'accepts settings with =' do
299
+ conf = nil
300
+ expect do
301
+ conf = Configuration.new do |c|
302
+ c.alpha = :value
303
+ end
304
+ end.to_not raise_error
305
+ conf.should_not be_nil
306
+ conf.alpha.should == :value
307
+ end
308
+
309
+ it 'can refer to an existing setting' do
310
+ conf = nil
311
+ expect do
312
+ conf = Configuration.new do |c|
313
+ c.alpha = :value
314
+ c.bravo = c.alpha
315
+ c.charlie c.bravo
316
+ end
317
+ end.to_not raise_error
318
+ conf.should_not be_nil
319
+ conf.alpha.should == :value
320
+ conf.bravo.should == :value
321
+ conf.charlie.should == :value
322
+ end
323
+
324
+ it 'returns value when creating/changing a setting' do
325
+ conf = nil
326
+ expect do
327
+ conf = Configuration.new do |c|
328
+ c.bravo = c.alpha = :value
329
+ end
330
+ end.to_not raise_error
331
+ conf.should_not be_nil
332
+ conf.alpha.should == :value
333
+ conf.bravo.should == :value
334
+ end
335
+
336
+ it 'supports nested configuration via do..end' do
337
+ conf = nil
338
+ expect do
339
+ conf = Configuration.new do |c1|
340
+ c1.alpha true
341
+ c1.bravo do |c2|
342
+ c2.charlie true
343
+ c2.delta do |c3|
344
+ c3.echo true
345
+ end
346
+ end
347
+ end
348
+ end.to_not raise_error
349
+ conf.should_not be_nil
350
+ conf.alpha.should be_true
351
+ conf.bravo.should be_a Configuration
352
+ conf.bravo.alpha should be_true
353
+ conf.bravo.charlie should be_true
354
+ conf.bravo.delta.should be_a Configuration
355
+ conf.bravo.delta.alpha.should be_true
356
+ conf.bravo.delta.charlie.should be_true
357
+ conf.bravo.delta.echo.should be_true
358
+ end
359
+
360
+ it 'supports nested configuration via {..}' do
361
+ conf = nil
362
+ expect do
363
+ conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
364
+ end.to_not raise_error
365
+ conf.should_not be_nil
366
+ conf.alpha.should be_true
367
+ conf.bravo.should be_a Configuration
368
+ conf.bravo.alpha should be_true
369
+ conf.bravo.charlie should be_true
370
+ conf.bravo.delta.should be_a Configuration
371
+ conf.bravo.delta.alpha.should be_true
372
+ conf.bravo.delta.charlie.should be_true
373
+ conf.bravo.delta.echo.should be_true
374
+ end
375
+
376
+ end # yield DSL
377
+
378
+ context 'instance_eval DSL' do
379
+
380
+ it 'accepts settings without =' do
381
+ conf = nil
382
+ expect do
383
+ conf = Configuration.new do
384
+ alpha :value
385
+ end
386
+ end.to_not raise_error
387
+ conf.should_not be_nil
388
+ conf.alpha.should == :value
389
+ end
390
+
391
+ it 'sets local variables with =' do
392
+ conf = alpha = nil
393
+ expect do
394
+ alpha = nil
395
+ conf = Configuration.new do
396
+ alpha = :value
397
+ bravo alpha
398
+ end
399
+ end.to_not raise_error
400
+ conf.should_not be_nil
401
+ conf.alpha.should be_nil
402
+ conf.bravo.should == :value
403
+ alpha.should == :value # local alpha set by matching variables
404
+ end
405
+
406
+ it 'can refer to an existing setting' do
407
+ conf = nil
408
+ expect do
409
+ conf = Configuration.new do
410
+ alpha :value
411
+ bravo alpha
412
+ charlie bravo
413
+ end
414
+ end.to_not raise_error
415
+ conf.should_not be_nil
416
+ conf.alpha.should == :value
417
+ conf.bravo.should == :value
418
+ conf.charlie.should == :value
419
+ end
420
+
421
+ it 'returns value when creating/changing a setting' do
422
+ conf = nil
423
+ expect do
424
+ conf = Configuration.new do
425
+ bravo alpha :value
426
+ end
427
+ end.to_not raise_error
428
+ conf.should_not be_nil
429
+ conf.alpha.should == :value
430
+ conf.bravo.should == :value
431
+ end
432
+
433
+ it 'supports nested configuration via do..end' do
434
+ conf = nil
435
+ expect do
436
+ conf = Configuration.new do
437
+ alpha true
438
+ bravo do
439
+ charlie true
440
+ delta do
441
+ echo true
442
+ end
443
+ end
444
+ end
445
+ end.to_not raise_error
446
+ conf.should_not be_nil
447
+ conf.alpha.should be_true
448
+ conf.bravo.should be_a Configuration
449
+ conf.bravo.alpha should be_true
450
+ conf.bravo.charlie should be_true
451
+ conf.bravo.delta.should be_a Configuration
452
+ conf.bravo.delta.alpha.should be_true
453
+ conf.bravo.delta.charlie.should be_true
454
+ conf.bravo.delta.echo.should be_true
455
+ end
456
+
457
+ it 'supports nested configuration via {..}' do
458
+ conf = nil
459
+ expect do
460
+ conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
461
+ end.to_not raise_error
462
+ conf.should_not be_nil
463
+ conf.alpha.should be_true
464
+ conf.bravo.should be_a Configuration
465
+ conf.bravo.alpha should be_true
466
+ conf.bravo.charlie should be_true
467
+ conf.bravo.delta.should be_a Configuration
468
+ conf.bravo.delta.alpha.should be_true
469
+ conf.bravo.delta.charlie.should be_true
470
+ conf.bravo.delta.echo.should be_true
471
+ end
472
+
473
+ end # instance_eval DSL
474
+
475
+ end # mode of usage
320
476
 
321
477
  context 'loads' do
322
478
 
323
- it 'simple eval DSL from string' do
324
- string = "alpha 1\nbravo 'two'\ncharlie 3.0\ndelta :four"
479
+ it 'simple instance_eval DSL from string' do
480
+ string = "alpha 1
481
+ bravo 'two'
482
+ charlie 3.0
483
+ delta :four"
325
484
  conf = nil
326
485
  expect do
327
486
  conf = Configuration.read string
@@ -333,8 +492,11 @@ describe Configuration do
333
492
  conf.delta.should == :four and conf.delta.should be_a Symbol
334
493
  end
335
494
 
336
- it 'simple eval DSL from file (by StringIO fake)' do
337
- io = StringIO.new "alpha 1\nbravo 'two'\ncharlie 3.0\ndelta :four"
495
+ it 'simple instance_eval DSL from file (by StringIO fake)' do
496
+ io = StringIO.new "alpha 1
497
+ bravo 'two'
498
+ charlie 3.0
499
+ delta :four"
338
500
  conf = nil
339
501
  expect do
340
502
  conf = Configuration.file io
@@ -346,10 +508,13 @@ describe Configuration do
346
508
  conf.delta.should == :four and conf.delta.should be_a Symbol
347
509
  end
348
510
 
349
- it 'simple eval DSL from file (by mock and expected methods)' do
511
+ it 'simple instance_eval DSL from file (by mock and expected methods)' do
350
512
  file = mock
351
513
  file.should_receive( :respond_to? ).with( :read ).and_return true
352
- file.should_receive( :read ).and_return "alpha 1\nbravo 'two'\ncharlie 3.0\ndelta :four"
514
+ file.should_receive( :read ).and_return "alpha 1
515
+ bravo 'two'
516
+ charlie 3.0
517
+ delta :four"
353
518
  conf = nil
354
519
  expect do
355
520
  conf = Configuration.file file
@@ -361,8 +526,11 @@ describe Configuration do
361
526
  conf.delta.should == :four and conf.delta.should be_a Symbol
362
527
  end
363
528
 
364
- it 'simple eval DSL from filename (by expected methods)' do
365
- File.should_receive( :read ).with( "filename" ).and_return "alpha 1\nbravo 'two'\ncharlie 3.0\ndelta :four"
529
+ it 'simple instance_eval DSL from filename (by expected methods)' do
530
+ File.should_receive( :read ).with( "filename" ).and_return "alpha 1
531
+ bravo 'two'
532
+ charlie 3.0
533
+ delta :four"
366
534
  conf = nil
367
535
  expect do
368
536
  conf = Configuration.file "filename"
@@ -374,7 +542,30 @@ describe Configuration do
374
542
  conf.delta.should == :four and conf.delta.should be_a Symbol
375
543
  end
376
544
 
377
- end
545
+ it 'complex instance_eval DSL from string' do
546
+ string = "alpha true
547
+ bravo do
548
+ charlie true
549
+ delta do
550
+ echo true
551
+ end
552
+ end"
553
+ conf = nil
554
+ expect do
555
+ conf = Configuration.read string
556
+ end.to_not raise_error
557
+ conf.should_not be_nil
558
+ conf.alpha.should be_true
559
+ conf.bravo.should be_a Configuration
560
+ conf.bravo.alpha should be_true
561
+ conf.bravo.charlie should be_true
562
+ conf.bravo.delta.should be_a Configuration
563
+ conf.bravo.delta.alpha.should be_true
564
+ conf.bravo.delta.charlie.should be_true
565
+ conf.bravo.delta.echo.should be_true
566
+ end
567
+
568
+ end # loads
378
569
 
379
570
  it 'delegates hash methods to internal hash' do
380
571
  conf = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iqeo-conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-28 00:00:00.000000000 Z
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -67,6 +67,7 @@ files:
67
67
  - pkg/iqeo-conf-0.0.2.gem
68
68
  - pkg/iqeo-conf-0.0.3.gem
69
69
  - pkg/iqeo-conf-0.0.4.gem
70
+ - pkg/iqeo-conf-0.0.5.gem
70
71
  - spec/configuration_spec.rb
71
72
  - spec/spec_helper.rb
72
73
  homepage: http://iqeo.github.com/iqeo-conf