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.
This is set by ConfineCollection.
# File lib/puppet/provider/confine/variable.rb, line 24 def initialize(values) super @values = @values.collect { |v| v.to_s.downcase } end
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/provider/confine/variable.rb, line 11 def self.summarize(confines) result = Hash.new { |hash, key| hash[key] = [] } confines.inject(result) { |total, confine| total[confine.name] += confine.values unless confine.valid?; total } end
Retrieve the value from facter
# File lib/puppet/provider/confine/variable.rb, line 20 def facter_value @facter_value ||= ::Facter.value(name).to_s.downcase end
# File lib/puppet/provider/confine/variable.rb, line 29 def message(value) "facter value '#{test_value}' for '#{self.name}' not in required list '#{values.join(",")}'" end
Compare the passed-in value to the retrieved value.
# File lib/puppet/provider/confine/variable.rb, line 34 def pass?(value) test_value.downcase.to_s == value.to_s.downcase end
# File lib/puppet/provider/confine/variable.rb, line 38 def reset # Reset the cache. We want to cache it during a given # run, but not across runs. @facter_value = nil end
# File lib/puppet/provider/confine/variable.rb, line 44 def valid? @values.include?(test_value.to_s.downcase) ensure reset end