mixlib-config 2.2.8 → 2.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mixlib/config/version.rb +1 -1
- data/lib/mixlib/config.rb +4 -2
- data/spec/mixlib/config_spec.rb +55 -49
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 892bd326a41b304ef7ca855f8dd070ec1ae7810ff265a938f5f16c4fce655858
|
4
|
+
data.tar.gz: 542afb3d0f64d556fe7b80f6ce2ab00b30f533a9f300c5d0ca4026af2ade2d8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67b63d216471aad6980910b820841bdc3053b8e8aec165995a936ed35c635b83ecafb975bb7940c0bde0670583eee2e294e7b1560822d6aea366ffd24c4c4822
|
7
|
+
data.tar.gz: 07a5aee20fb6e06ee9a0cdbbcc581cfb87956668bcab76c8d607a147ec99dfb0918036d1cad2593ba361854c54ae14e55682459eb29239e1be8ea7de921febc3
|
data/lib/mixlib/config.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
3
|
# Author:: Nuo Yan (<nuo@chef.io>)
|
4
4
|
# Author:: Christopher Brown (<cb@chef.io>)
|
5
|
-
# Copyright:: Copyright (c) 2008-
|
5
|
+
# Copyright:: Copyright (c) 2008-2018, Chef Software Inc.
|
6
6
|
# License:: Apache License, Version 2.0
|
7
7
|
#
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -152,10 +152,12 @@ module Mixlib
|
|
152
152
|
# === Returns
|
153
153
|
# <True>:: If the config option exists
|
154
154
|
# <False>:: If the config option does not exist
|
155
|
-
def
|
155
|
+
def key?(key)
|
156
156
|
configuration.has_key?(key.to_sym)
|
157
157
|
end
|
158
158
|
|
159
|
+
alias_method :has_key?, :key?
|
160
|
+
|
159
161
|
# Resets a config option to its default.
|
160
162
|
#
|
161
163
|
# === Parameters
|
data/spec/mixlib/config_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
-
# Copyright:: Copyright (c) 2008-
|
3
|
+
# Copyright:: Copyright (c) 2008-2018, Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -142,7 +142,7 @@ describe Mixlib::Config do
|
|
142
142
|
ConfigIt.configure { |c| c[:cookbook_path] = "monkey_rabbit"; c[:otherthing] = "boo" }
|
143
143
|
end
|
144
144
|
|
145
|
-
{ :
|
145
|
+
{ cookbook_path: "monkey_rabbit", otherthing: "boo" }.each do |k, v|
|
146
146
|
it "allows you to retrieve the config value for #{k} via []" do
|
147
147
|
expect(ConfigIt[k]).to eql(v)
|
148
148
|
end
|
@@ -162,6 +162,12 @@ describe Mixlib::Config do
|
|
162
162
|
expect(ConfigIt.has_key?(:monkey)).to be true
|
163
163
|
end
|
164
164
|
|
165
|
+
it "returns true or false with key?" do
|
166
|
+
expect(ConfigIt.key?(:monkey2)).to be false
|
167
|
+
ConfigIt[:monkey2] = "gotcha"
|
168
|
+
expect(ConfigIt.key?(:monkey2)).to be true
|
169
|
+
end
|
170
|
+
|
165
171
|
describe "when a class method override writer exists" do
|
166
172
|
before do
|
167
173
|
@klass = Class.new
|
@@ -301,12 +307,12 @@ describe Mixlib::Config do
|
|
301
307
|
end
|
302
308
|
|
303
309
|
it "save with include_defaults should save all defaults" do
|
304
|
-
expect(@klass.save(true)).to eql({ :
|
310
|
+
expect(@klass.save(true)).to eql({ attr: 4 })
|
305
311
|
end
|
306
312
|
|
307
313
|
it "saves the new value if it gets set" do
|
308
314
|
@klass.attr 5
|
309
|
-
expect((saved = @klass.save)).to eql({ :
|
315
|
+
expect((saved = @klass.save)).to eql({ attr: 5 })
|
310
316
|
@klass.reset
|
311
317
|
expect(@klass.attr).to eql(4)
|
312
318
|
@klass.restore(saved)
|
@@ -315,11 +321,11 @@ describe Mixlib::Config do
|
|
315
321
|
|
316
322
|
it "saves the new value even if it is set to its default value" do
|
317
323
|
@klass.attr 4
|
318
|
-
expect((saved = @klass.save)).to eql({ :
|
324
|
+
expect((saved = @klass.save)).to eql({ attr: 4 })
|
319
325
|
@klass.reset
|
320
326
|
expect(@klass.save).to eql({})
|
321
327
|
@klass.restore(saved)
|
322
|
-
expect(@klass.save).to eql({ :
|
328
|
+
expect(@klass.save).to eql({ attr: 4 })
|
323
329
|
end
|
324
330
|
end
|
325
331
|
|
@@ -369,12 +375,12 @@ describe Mixlib::Config do
|
|
369
375
|
end
|
370
376
|
|
371
377
|
it "save with include_defaults should save all defaults" do
|
372
|
-
expect(@klass.save(true)).to eql({ :
|
378
|
+
expect(@klass.save(true)).to eql({ attr: 8, x: 4 })
|
373
379
|
end
|
374
380
|
|
375
381
|
it "saves the new value if it gets set" do
|
376
382
|
@klass.attr 5
|
377
|
-
expect((saved = @klass.save)).to eql({ :
|
383
|
+
expect((saved = @klass.save)).to eql({ attr: 5 })
|
378
384
|
@klass.reset
|
379
385
|
expect(@klass.attr).to eql(8)
|
380
386
|
@klass.restore(saved)
|
@@ -383,11 +389,11 @@ describe Mixlib::Config do
|
|
383
389
|
|
384
390
|
it "saves the new value even if it is set to its default value" do
|
385
391
|
@klass.attr 8
|
386
|
-
expect((saved = @klass.save)).to eql({ :
|
392
|
+
expect((saved = @klass.save)).to eql({ attr: 8 })
|
387
393
|
@klass.reset
|
388
394
|
expect(@klass.save).to eql({})
|
389
395
|
@klass.restore(saved)
|
390
|
-
expect(@klass.save).to eql({ :
|
396
|
+
expect(@klass.save).to eql({ attr: 8 })
|
391
397
|
end
|
392
398
|
end
|
393
399
|
|
@@ -410,12 +416,12 @@ describe Mixlib::Config do
|
|
410
416
|
end
|
411
417
|
|
412
418
|
it "save with include_defaults should save all defaults" do
|
413
|
-
expect(@klass.save(true)).to eql({ :
|
419
|
+
expect(@klass.save(true)).to eql({ attr: [] })
|
414
420
|
end
|
415
421
|
|
416
422
|
it "saves the new value if it gets set" do
|
417
423
|
@klass.attr << "x"
|
418
|
-
expect((saved = @klass.save)).to eql({ :
|
424
|
+
expect((saved = @klass.save)).to eql({ attr: [ "x" ] })
|
419
425
|
@klass.reset
|
420
426
|
expect(@klass.attr).to eql([])
|
421
427
|
@klass.restore(saved)
|
@@ -424,11 +430,11 @@ describe Mixlib::Config do
|
|
424
430
|
|
425
431
|
it "saves the new value even if it is set to its default value" do
|
426
432
|
@klass.attr = []
|
427
|
-
expect((saved = @klass.save)).to eql({ :
|
433
|
+
expect((saved = @klass.save)).to eql({ attr: [] })
|
428
434
|
@klass.reset
|
429
435
|
expect(@klass.save).to eql({})
|
430
436
|
@klass.restore(saved)
|
431
|
-
expect(@klass.save).to eql({ :
|
437
|
+
expect(@klass.save).to eql({ attr: [] })
|
432
438
|
end
|
433
439
|
end
|
434
440
|
|
@@ -451,25 +457,25 @@ describe Mixlib::Config do
|
|
451
457
|
end
|
452
458
|
|
453
459
|
it "save with include_defaults should save all defaults" do
|
454
|
-
expect(@klass.save(true)).to eql({ :
|
460
|
+
expect(@klass.save(true)).to eql({ attr: {} })
|
455
461
|
end
|
456
462
|
|
457
463
|
it "saves the new value if it gets set" do
|
458
464
|
@klass.attr[:hi] = "lo"
|
459
|
-
expect((saved = @klass.save)).to eql({ :
|
465
|
+
expect((saved = @klass.save)).to eql({ attr: { hi: "lo" } })
|
460
466
|
@klass.reset
|
461
467
|
expect(@klass.attr).to eql({})
|
462
468
|
@klass.restore(saved)
|
463
|
-
expect(@klass.save).to eql({ :
|
469
|
+
expect(@klass.save).to eql({ attr: { hi: "lo" } })
|
464
470
|
end
|
465
471
|
|
466
472
|
it "saves the new value even if it is set to its default value" do
|
467
473
|
@klass.attr = {}
|
468
|
-
expect((saved = @klass.save)).to eql({ :
|
474
|
+
expect((saved = @klass.save)).to eql({ attr: {} })
|
469
475
|
@klass.reset
|
470
476
|
expect(@klass.save).to eql({})
|
471
477
|
@klass.restore(saved)
|
472
|
-
expect(@klass.save).to eql({ :
|
478
|
+
expect(@klass.save).to eql({ attr: {} })
|
473
479
|
end
|
474
480
|
end
|
475
481
|
|
@@ -492,12 +498,12 @@ describe Mixlib::Config do
|
|
492
498
|
end
|
493
499
|
|
494
500
|
it "save with include_defaults should save all defaults" do
|
495
|
-
expect(@klass.save(true)).to eql({ :
|
501
|
+
expect(@klass.save(true)).to eql({ attr: "hello" })
|
496
502
|
end
|
497
503
|
|
498
504
|
it "saves the new value if it gets set" do
|
499
505
|
@klass.attr << " world"
|
500
|
-
expect((saved = @klass.save)).to eql({ :
|
506
|
+
expect((saved = @klass.save)).to eql({ attr: "hello world" })
|
501
507
|
@klass.reset
|
502
508
|
expect(@klass.attr).to eql("hello")
|
503
509
|
@klass.restore(saved)
|
@@ -506,11 +512,11 @@ describe Mixlib::Config do
|
|
506
512
|
|
507
513
|
it "saves the new value even if it is set to its default value" do
|
508
514
|
@klass.attr "hello world"
|
509
|
-
expect((saved = @klass.save)).to eql({ :
|
515
|
+
expect((saved = @klass.save)).to eql({ attr: "hello world" })
|
510
516
|
@klass.reset
|
511
517
|
expect(@klass.save).to eql({})
|
512
518
|
@klass.restore(saved)
|
513
|
-
expect(@klass.save).to eql({ :
|
519
|
+
expect(@klass.save).to eql({ attr: "hello world" })
|
514
520
|
end
|
515
521
|
end
|
516
522
|
|
@@ -554,12 +560,12 @@ describe Mixlib::Config do
|
|
554
560
|
end
|
555
561
|
|
556
562
|
it "save with include_defaults should save all defaults" do
|
557
|
-
expect(@klass.save(true)).to eql({ :
|
563
|
+
expect(@klass.save(true)).to eql({ attr: 4 })
|
558
564
|
end
|
559
565
|
|
560
566
|
it "saves the new value if it gets set" do
|
561
567
|
@klass.attr 5
|
562
|
-
expect((saved = @klass.save)).to eql({ :
|
568
|
+
expect((saved = @klass.save)).to eql({ attr: 5 })
|
563
569
|
@klass.reset
|
564
570
|
expect(@klass.attr).to eql(4)
|
565
571
|
@klass.restore(saved)
|
@@ -568,11 +574,11 @@ describe Mixlib::Config do
|
|
568
574
|
|
569
575
|
it "saves the new value even if it is set to its default value" do
|
570
576
|
@klass.attr 4
|
571
|
-
expect((saved = @klass.save)).to eql({ :
|
577
|
+
expect((saved = @klass.save)).to eql({ attr: 4 })
|
572
578
|
@klass.reset
|
573
579
|
expect(@klass.save).to eql({})
|
574
580
|
@klass.restore(saved)
|
575
|
-
expect(@klass.save).to eql({ :
|
581
|
+
expect(@klass.save).to eql({ attr: 4 })
|
576
582
|
end
|
577
583
|
end
|
578
584
|
|
@@ -631,12 +637,12 @@ describe Mixlib::Config do
|
|
631
637
|
end
|
632
638
|
|
633
639
|
it "save with include_defaults should save all defaults" do
|
634
|
-
expect(@klass.save(true)).to eql({ :
|
640
|
+
expect(@klass.save(true)).to eql({ attr: 4 })
|
635
641
|
end
|
636
642
|
|
637
643
|
it "saves the new value if it gets set" do
|
638
644
|
@klass.attr 5
|
639
|
-
expect((saved = @klass.save)).to eql({ :
|
645
|
+
expect((saved = @klass.save)).to eql({ attr: 10 })
|
640
646
|
@klass.reset
|
641
647
|
expect(@klass.attr).to eql(4)
|
642
648
|
@klass.restore(saved)
|
@@ -645,11 +651,11 @@ describe Mixlib::Config do
|
|
645
651
|
|
646
652
|
it "saves the new value even if it is set to its default value" do
|
647
653
|
@klass.attr 4
|
648
|
-
expect((saved = @klass.save)).to eql({ :
|
654
|
+
expect((saved = @klass.save)).to eql({ attr: 8 })
|
649
655
|
@klass.reset
|
650
656
|
expect(@klass.save).to eql({})
|
651
657
|
@klass.restore(saved)
|
652
|
-
expect(@klass.save).to eql({ :
|
658
|
+
expect(@klass.save).to eql({ attr: 8 })
|
653
659
|
end
|
654
660
|
end
|
655
661
|
|
@@ -705,12 +711,12 @@ describe Mixlib::Config do
|
|
705
711
|
end
|
706
712
|
|
707
713
|
it "save with include_defaults should save all defaults" do
|
708
|
-
expect(@klass.save(true)).to eql({ :
|
714
|
+
expect(@klass.save(true)).to eql({ attr: 4 })
|
709
715
|
end
|
710
716
|
|
711
717
|
it "saves the new value if it gets set" do
|
712
718
|
@klass.attr 5
|
713
|
-
expect((saved = @klass.save)).to eql({ :
|
719
|
+
expect((saved = @klass.save)).to eql({ attr: 10 })
|
714
720
|
@klass.reset
|
715
721
|
expect(@klass.attr).to eql(4)
|
716
722
|
@klass.restore(saved)
|
@@ -719,11 +725,11 @@ describe Mixlib::Config do
|
|
719
725
|
|
720
726
|
it "saves the new value even if it is set to its default value" do
|
721
727
|
@klass.attr 2
|
722
|
-
expect((saved = @klass.save)).to eql({ :
|
728
|
+
expect((saved = @klass.save)).to eql({ attr: 4 })
|
723
729
|
@klass.reset
|
724
730
|
expect(@klass.save).to eql({})
|
725
731
|
@klass.restore(saved)
|
726
|
-
expect(@klass.save).to eql({ :
|
732
|
+
expect(@klass.save).to eql({ attr: 4 })
|
727
733
|
end
|
728
734
|
end
|
729
735
|
|
@@ -755,12 +761,12 @@ describe Mixlib::Config do
|
|
755
761
|
end
|
756
762
|
|
757
763
|
it "setting the entire context to a hash with default value overridden sets the value" do
|
758
|
-
@klass.blah = { :
|
764
|
+
@klass.blah = { x: 10 }
|
759
765
|
expect(@klass.blah.x).to eql(10)
|
760
766
|
end
|
761
767
|
|
762
768
|
it "setting the entire context to a hash sets non-default values" do
|
763
|
-
@klass.blah = { :
|
769
|
+
@klass.blah = { y: 10 }
|
764
770
|
expect(@klass.blah.x).to eql(5)
|
765
771
|
expect(@klass.blah.y).to eql(10)
|
766
772
|
end
|
@@ -768,7 +774,7 @@ describe Mixlib::Config do
|
|
768
774
|
it "setting the entire context to a hash deletes any non-default values and resets default values" do
|
769
775
|
@klass.blah.x = 10
|
770
776
|
@klass.blah.y = 10
|
771
|
-
@klass.blah = { :
|
777
|
+
@klass.blah = { z: 10 }
|
772
778
|
expect(@klass.blah.x).to eql(5)
|
773
779
|
expect(@klass.blah.y).to be_nil
|
774
780
|
expect(@klass.blah.z).to eql(10)
|
@@ -804,17 +810,17 @@ describe Mixlib::Config do
|
|
804
810
|
end
|
805
811
|
|
806
812
|
it "save with include_defaults should save all defaults" do
|
807
|
-
expect(@klass.save(true)).to eql({ :
|
813
|
+
expect(@klass.save(true)).to eql({ blah: { x: 5 } })
|
808
814
|
end
|
809
815
|
|
810
816
|
it "saves any new values that are set in the context" do
|
811
817
|
@klass.blah.x = 10
|
812
|
-
expect((saved = @klass.save)).to eql({ :
|
818
|
+
expect((saved = @klass.save)).to eql({ blah: { x: 10 } })
|
813
819
|
@klass.reset
|
814
820
|
expect(@klass.blah.x).to eql(5)
|
815
821
|
@klass.restore(saved)
|
816
822
|
expect(@klass.blah.x).to eql(10)
|
817
|
-
expect(@klass.save).to eql({ :
|
823
|
+
expect(@klass.save).to eql({ blah: { x: 10 } })
|
818
824
|
end
|
819
825
|
|
820
826
|
# this tests existing (somewhat bizzare) behavior of mixlib-config where testing to
|
@@ -880,37 +886,37 @@ describe Mixlib::Config do
|
|
880
886
|
end
|
881
887
|
|
882
888
|
it "save with include_defaults should save all defaults" do
|
883
|
-
expect(@klass.save(true)).to eql({ :
|
889
|
+
expect(@klass.save(true)).to eql({ blah: { yarr: { x: 5, y: 6 } } })
|
884
890
|
end
|
885
891
|
|
886
892
|
it "saves any new values that are set in the context" do
|
887
893
|
@klass.blah.yarr.x = 10
|
888
894
|
@klass.blah.yarr.y = 11
|
889
|
-
expect((saved = @klass.save)).to eql({ :
|
895
|
+
expect((saved = @klass.save)).to eql({ blah: { yarr: { x: 10, y: 11 } } })
|
890
896
|
@klass.reset
|
891
897
|
expect(@klass.blah.yarr.x).to eql(5)
|
892
898
|
expect(@klass.blah.yarr.y).to eql(6)
|
893
899
|
@klass.restore(saved)
|
894
900
|
expect(@klass.blah.yarr.x).to eql(10)
|
895
901
|
expect(@klass.blah.yarr.y).to eql(11)
|
896
|
-
expect(@klass.save).to eql({ :
|
902
|
+
expect(@klass.save).to eql({ blah: { yarr: { x: 10, y: 11 } } })
|
897
903
|
end
|
898
904
|
|
899
905
|
it "restores defaults not included in saved data" do
|
900
|
-
@klass.restore( :
|
906
|
+
@klass.restore( blah: { yarr: { x: 10 } } )
|
901
907
|
expect(@klass.blah.yarr.x).to eql(10)
|
902
908
|
expect(@klass.blah.yarr.y).to eql(6)
|
903
909
|
end
|
904
910
|
|
905
911
|
it "removes added properties not included in saved state" do
|
906
912
|
@klass.blah.yarr.z = 12
|
907
|
-
@klass.restore( :
|
913
|
+
@klass.restore( blah: { yarr: { x: 10 } } )
|
908
914
|
expect(@klass.blah.yarr.x).to eql(10)
|
909
915
|
expect(@klass.blah.yarr.z).to eql(nil)
|
910
916
|
end
|
911
917
|
|
912
918
|
it "can set a config context from another context" do
|
913
|
-
@klass.blah.blyme = { :
|
919
|
+
@klass.blah.blyme = { x: 7 }
|
914
920
|
blyme = @klass.blah.blyme
|
915
921
|
@klass.blah.yarr.x = 12
|
916
922
|
@klass.blah.yarr = blyme
|
@@ -934,7 +940,7 @@ describe Mixlib::Config do
|
|
934
940
|
end
|
935
941
|
|
936
942
|
it "save with defaults saves the hash for the config_context" do
|
937
|
-
expect(@klass.save(true)).to eql({ :
|
943
|
+
expect(@klass.save(true)).to eql({ blah: {} })
|
938
944
|
end
|
939
945
|
end
|
940
946
|
|
@@ -952,7 +958,7 @@ describe Mixlib::Config do
|
|
952
958
|
end
|
953
959
|
|
954
960
|
it "save with defaults saves the hash for the config_context" do
|
955
|
-
expect(@klass.save(true)).to eql({ :
|
961
|
+
expect(@klass.save(true)).to eql({ blah: {} })
|
956
962
|
end
|
957
963
|
end
|
958
964
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixlib-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|