File tree 2 files changed +18
-2
lines changed
lib/facter/custom_facts/util
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ def to_s
35
35
end
36
36
37
37
# Evaluate the fact, returning true or false.
38
- # if we have a block paramter then we only evaluate that instead
38
+ # if we have a block parameter then we only evaluate that instead
39
39
def true?
40
40
if @block && !@fact
41
41
begin
@@ -54,9 +54,11 @@ def true?
54
54
55
55
return false if value . nil?
56
56
57
+ # We call the block with both the downcased and raw fact value for
58
+ # backwards-compatibility.
57
59
if @block
58
60
begin
59
- return !!@block . call ( value )
61
+ return !!@block . call ( value ) || !! @block . call ( fact . value ) # rubocop:disable Style/DoubleNegation
60
62
rescue StandardError => e
61
63
log . debug "Confine raised #{ e . class } #{ e } "
62
64
return false
Original file line number Diff line number Diff line change @@ -126,6 +126,20 @@ def confined(fact_value, *confines)
126
126
expect ( confine . true? ) . to be true
127
127
end
128
128
129
+ it 'accepts and evaluate a block argument against the fact while respecting case' do
130
+ allow ( fact ) . to receive ( :value ) . and_return 'Foo'
131
+ confine = LegacyFacter ::Util ::Confine . new ( :yay ) { |f | f == 'Foo' }
132
+ expect ( confine . true? ) . to be true
133
+ end
134
+
135
+ it 'accepts and evaluate multiple block arguments' do
136
+ allow ( fact ) . to receive ( :value ) . and_return 'bar'
137
+ first_confine = LegacyFacter ::Util ::Confine . new ( :yay ) { |f | f == 'foo' }
138
+ second_confine = LegacyFacter ::Util ::Confine . new ( :yay ) { |f | f == 'bar' }
139
+ expect ( first_confine . true? ) . to be false
140
+ expect ( second_confine . true? ) . to be true
141
+ end
142
+
129
143
it 'returns false if the block raises a StandardError when checking a fact' do
130
144
allow ( fact ) . to receive ( :value ) . and_return 'foo'
131
145
confine = LegacyFacter ::Util ::Confine . new ( :yay ) { |_f | raise StandardError }
You can’t perform that action at this time.
0 commit comments