mixlib-config 2.2.3 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -3
- data/lib/mixlib/config.rb +14 -3
- data/lib/mixlib/config/version.rb +1 -1
- data/spec/mixlib/config_spec.rb +27 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8af6841c4facccc997e4f034d65114d5cb37493
|
4
|
+
data.tar.gz: 83cce1c086a8ced0d664a0c69fbda32984abbf49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec9e172a49462573a09580ecd568ce2fa8c3827f48d38c93a5288269481d0b023e111a8acadd801f0682f7081ea56a70f9201747d90dff55f09f2867a648256d
|
7
|
+
data.tar.gz: 46eeefec4cd14ba0283461a319955c444e5ab0b0f4213ed4fe85c309ccf3bc48b0687b0fb2d1b462b4914b2e89b0d3c473194dca3f00b675dd28658671726216
|
data/README.md
CHANGED
@@ -59,11 +59,30 @@ Often you want to be able to group configuration options to provide a common con
|
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
62
|
-
The user can write their config file
|
62
|
+
The user can write their config file in one of three formats:
|
63
63
|
|
64
|
+
#### Method Style
|
64
65
|
```ruby
|
65
|
-
|
66
|
-
|
66
|
+
logging.base_filename 'superlog'
|
67
|
+
logging.max_log_files 2
|
68
|
+
```
|
69
|
+
|
70
|
+
#### Block Style
|
71
|
+
Using this format the block is executed in the context, so all configurables on that context is directly accessible
|
72
|
+
```ruby
|
73
|
+
logging do
|
74
|
+
base_filename 'superlog'
|
75
|
+
max_log_files 2
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
#### Block with Argument Style
|
80
|
+
Using this format the context is given to the block as an argument
|
81
|
+
```ruby
|
82
|
+
logging do |l|
|
83
|
+
l.base_filename = 'superlog'
|
84
|
+
l.max_log_files = 2
|
85
|
+
end
|
67
86
|
```
|
68
87
|
|
69
88
|
You can access these variables thus:
|
data/lib/mixlib/config.rb
CHANGED
@@ -174,6 +174,7 @@ module Mixlib
|
|
174
174
|
end
|
175
175
|
result
|
176
176
|
end
|
177
|
+
alias :to_hash :save
|
177
178
|
|
178
179
|
# Restore non-default values from the given hash.
|
179
180
|
#
|
@@ -416,7 +417,7 @@ module Mixlib
|
|
416
417
|
if configurables.has_key?(symbol)
|
417
418
|
configurables[symbol].set(self.configuration, value)
|
418
419
|
elsif config_contexts.has_key?(symbol)
|
419
|
-
config_contexts[symbol].restore(value)
|
420
|
+
config_contexts[symbol].restore(value.to_hash)
|
420
421
|
else
|
421
422
|
if config_strict_mode == :warn
|
422
423
|
Chef::Log.warn("Setting unsupported config value #{symbol}.")
|
@@ -461,8 +462,18 @@ module Mixlib
|
|
461
462
|
internal_set(symbol, value)
|
462
463
|
end
|
463
464
|
# Getter
|
464
|
-
meta.send :define_method, symbol do |*args|
|
465
|
-
|
465
|
+
meta.send :define_method, symbol do |*args, &block|
|
466
|
+
# If a block was given, eval it in the context
|
467
|
+
if block
|
468
|
+
# If the block expects no arguments, then instance_eval
|
469
|
+
if block.arity == 0
|
470
|
+
internal_get(symbol).instance_eval(&block)
|
471
|
+
else # yield to the block
|
472
|
+
block.yield(internal_get(symbol))
|
473
|
+
end
|
474
|
+
else
|
475
|
+
internal_get_or_set(symbol, *args)
|
476
|
+
end
|
466
477
|
end
|
467
478
|
end
|
468
479
|
end
|
data/spec/mixlib/config_spec.rb
CHANGED
@@ -754,6 +754,24 @@ describe Mixlib::Config do
|
|
754
754
|
expect(@klass.blah.z).to eql(10)
|
755
755
|
end
|
756
756
|
|
757
|
+
it "setting the context values in a block overrides the default values" do
|
758
|
+
@klass.blah do
|
759
|
+
x 10
|
760
|
+
y 20
|
761
|
+
end
|
762
|
+
@klass.blah.x.should == 10
|
763
|
+
@klass.blah.y.should == 20
|
764
|
+
end
|
765
|
+
|
766
|
+
it "setting the context values in a yielded block overrides the default values" do
|
767
|
+
@klass.blah do |b|
|
768
|
+
b.x = 10
|
769
|
+
b.y = 20
|
770
|
+
end
|
771
|
+
@klass.blah.x.should == 10
|
772
|
+
@klass.blah.y.should == 20
|
773
|
+
end
|
774
|
+
|
757
775
|
it "after reset of the parent class, children are reset" do
|
758
776
|
@klass.blah.x = 10
|
759
777
|
expect(@klass.blah.x).to eql(10)
|
@@ -850,12 +868,20 @@ describe Mixlib::Config do
|
|
850
868
|
expect(@klass.blah.yarr.y).to eql(6)
|
851
869
|
end
|
852
870
|
|
853
|
-
it "
|
871
|
+
it "removes added properties not included in saved state" do
|
854
872
|
@klass.blah.yarr.z = 12
|
855
873
|
@klass.restore( :blah => { :yarr => { :x => 10 } } )
|
856
874
|
expect(@klass.blah.yarr.x).to eql(10)
|
857
875
|
expect(@klass.blah.yarr.z).to eql(nil)
|
858
876
|
end
|
877
|
+
|
878
|
+
it "can set a config context from another context" do
|
879
|
+
@klass.blah.blyme = { :x => 7 }
|
880
|
+
blyme = @klass.blah.blyme
|
881
|
+
@klass.blah.yarr.x = 12
|
882
|
+
@klass.blah.yarr = blyme
|
883
|
+
expect(@klass.blah.yarr.x).to eql(7)
|
884
|
+
end
|
859
885
|
end
|
860
886
|
|
861
887
|
describe "When a config_context with no defaulted values exists" do
|
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.4
|
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: 2016-
|
11
|
+
date: 2016-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|