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 9 def passing_value 10 raise NotImplementedError, "The Boolean confine %{confine} must provide the passing value." % { confine: self.class.name } 11 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 23 def values 24 # Note that Puppet::Confine's constructor ensures that @values 25 # will always be an array, even if a lambda's passed in. This is 26 # why we have the length == 1 check. 27 unless @values.length == 1 && @values.first.respond_to?(:call) 28 return @values 29 end 30 31 # We have a lambda. Here, we want to enforce "cache positive" 32 # behavior, which is to cache the result _if_ it evaluates to 33 # the passing value (i.e. the class name). 34 35 return @cached_value unless @cached_value.nil? 36 37 # Double negate to coerce the value into a Boolean 38 calculated_value = !! @values.first.call 39 if calculated_value == passing_value 40 @cached_value = [calculated_value] 41 end 42 43 [calculated_value] 44 end