module Puppet::Confine::Boolean
Public Instance Methods
passing_value()
click to toggle source
Returns the passing value for the Boolean
confine.
# File lib/puppet/confine/boolean.rb 8 def passing_value 9 raise NotImplementedError, "The Boolean confine %{confine} must provide the passing value." % { confine: self.class.name } 10 end
values()
click to toggle source
The Boolean
confines 'true' and 'false' let the user specify two types of values:
* A lambda for lazy evaluation. This would be something like confine :true => lambda { true } * A single Boolean value, or an array of Boolean values. This would be something like confine :true => true OR confine :true => [true, false, false, true]
This override distinguishes between the two cases.
# File lib/puppet/confine/boolean.rb 22 def values 23 # Note that Puppet::Confine's constructor ensures that @values 24 # will always be an array, even if a lambda's passed in. This is 25 # why we have the length == 1 check. 26 unless @values.length == 1 && @values.first.respond_to?(:call) 27 return @values 28 end 29 30 # We have a lambda. Here, we want to enforce "cache positive" 31 # behavior, which is to cache the result _if_ it evaluates to 32 # the passing value (i.e. the class name). 33 34 return @cached_value unless @cached_value.nil? 35 36 # Double negate to coerce the value into a Boolean 37 calculated_value = !! @values.first.call 38 if calculated_value == passing_value 39 @cached_value = [calculated_value] 40 end 41 42 [calculated_value] 43 end