class Puppet::Confine::Variable
Require a specific value for a variable, either a Puppet
setting or a Facter value. This class is a bit weird because the name is set explicitly by the ConfineCollection class – from this class, it's not obvious how the name would ever get set.
Attributes
name[RW]
This is set by ConfineCollection.
Public Class Methods
new(values)
click to toggle source
Calls superclass method
Puppet::Confine::new
# File lib/puppet/confine/variable.rb 24 def initialize(values) 25 super 26 @values = @values.collect { |v| v.to_s.downcase } 27 end
summarize(confines)
click to toggle source
Provide a hash summary of failing confines – the key of the hash is the name of the confine, and the value is the missing yet required values. Only returns failed values, not all required values.
# File lib/puppet/confine/variable.rb 11 def self.summarize(confines) 12 result = Hash.new { |hash, key| hash[key] = [] } 13 confines.inject(result) { |total, confine| total[confine.name] += confine.values unless confine.valid?; total } 14 end
Public Instance Methods
facter_value()
click to toggle source
Retrieve the value from facter
# File lib/puppet/confine/variable.rb 20 def facter_value 21 @facter_value ||= ::Facter.value(name).to_s.downcase 22 end
message(value)
click to toggle source
# File lib/puppet/confine/variable.rb 29 def message(value) 30 "facter value '#{test_value}' for '#{self.name}' not in required list '#{values.join(",")}'" 31 end
pass?(value)
click to toggle source
Compare the passed-in value to the retrieved value.
# File lib/puppet/confine/variable.rb 34 def pass?(value) 35 test_value.downcase.to_s == value.to_s.downcase 36 end
reset()
click to toggle source
# File lib/puppet/confine/variable.rb 38 def reset 39 # Reset the cache. We want to cache it during a given 40 # run, but not across runs. 41 @facter_value = nil 42 end
valid?()
click to toggle source
# File lib/puppet/confine/variable.rb 44 def valid? 45 @values.include?(test_value.to_s.downcase) 46 ensure 47 reset 48 end
Private Instance Methods
setting?()
click to toggle source
# File lib/puppet/confine/variable.rb 52 def setting? 53 Puppet.settings.valid?(name) 54 end
test_value()
click to toggle source
# File lib/puppet/confine/variable.rb 56 def test_value 57 setting? ? Puppet.settings[name] : facter_value 58 end