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 25 def initialize(values) 26 super 27 @values = @values.collect { |v| v.to_s.downcase } 28 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 12 def self.summarize(confines) 13 result = Hash.new { |hash, key| hash[key] = [] } 14 confines.inject(result) { |total, confine| total[confine.name] += confine.values unless confine.valid?; total } 15 end
Public Instance Methods
facter_value()
click to toggle source
Retrieve the value from facter
# File lib/puppet/confine/variable.rb 21 def facter_value 22 @facter_value ||= Puppet.runtime[:facter].value(name).to_s.downcase 23 end
message(value)
click to toggle source
# File lib/puppet/confine/variable.rb 30 def message(value) 31 "facter value '#{test_value}' for '#{self.name}' not in required list '#{values.join(",")}'" 32 end
pass?(value)
click to toggle source
Compare the passed-in value to the retrieved value.
# File lib/puppet/confine/variable.rb 35 def pass?(value) 36 test_value.downcase.to_s == value.to_s.downcase 37 end
reset()
click to toggle source
# File lib/puppet/confine/variable.rb 39 def reset 40 # Reset the cache. We want to cache it during a given 41 # run, but not across runs. 42 @facter_value = nil 43 end
valid?()
click to toggle source
# File lib/puppet/confine/variable.rb 45 def valid? 46 @values.include?(test_value.to_s.downcase) 47 ensure 48 reset 49 end
Private Instance Methods
setting?()
click to toggle source
# File lib/puppet/confine/variable.rb 53 def setting? 54 Puppet.settings.valid?(name) 55 end
test_value()
click to toggle source
# File lib/puppet/confine/variable.rb 57 def test_value 58 setting? ? Puppet.settings[name] : facter_value 59 end