Sha256: 65052f129627d8ed4d3624a88b527160990a3564718bdd8c915ad0968e97faec

Contents?: true

Size: 1.64 KB

Versions: 96

Compression:

Stored size: 1.64 KB

Contents

require 'puppet/provider/confine'

# 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.
class Puppet::Provider::Confine::Variable < Puppet::Provider::Confine
  # 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.
  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

  # This is set by ConfineCollection.
  attr_accessor :name

  # Retrieve the value from facter
  def facter_value
    @facter_value ||= ::Facter.value(name).to_s.downcase
  end

  def initialize(values)
    super
    @values = @values.collect { |v| v.to_s.downcase }
  end

  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.
  def pass?(value)
    test_value.downcase.to_s == value.to_s.downcase
  end

  def reset
    # Reset the cache.  We want to cache it during a given
    # run, but not across runs.
    @facter_value = nil
  end

  def valid?
    @values.include?(test_value.to_s.downcase)
  ensure
    reset
  end

  private

  def setting?
    Puppet.settings.valid?(name)
  end

  def test_value
    setting? ? Puppet.settings[name] : facter_value
  end
end

Version data entries

96 entries across 96 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/provider/confine/variable.rb
puppet-parse-0.1.3 lib/vendor/puppet/provider/confine/variable.rb
puppet-parse-0.1.2 lib/vendor/puppet/provider/confine/variable.rb
puppet-parse-0.1.1 lib/vendor/puppet/provider/confine/variable.rb
puppet-2.7.26 lib/puppet/provider/confine/variable.rb
puppet-2.7.25 lib/puppet/provider/confine/variable.rb
puppet-2.7.24 lib/puppet/provider/confine/variable.rb
puppet-3.3.2 lib/puppet/provider/confine/variable.rb
puppet-3.3.1 lib/puppet/provider/confine/variable.rb
puppet-3.3.1.rc3 lib/puppet/provider/confine/variable.rb
puppet-3.3.1.rc2 lib/puppet/provider/confine/variable.rb
puppet-3.3.1.rc1 lib/puppet/provider/confine/variable.rb
puppet-3.3.0 lib/puppet/provider/confine/variable.rb
puppet-3.3.0.rc3 lib/puppet/provider/confine/variable.rb
puppet-3.3.0.rc2 lib/puppet/provider/confine/variable.rb
puppet-3.2.4 lib/puppet/provider/confine/variable.rb
puppet-2.7.23 lib/puppet/provider/confine/variable.rb
puppet-3.2.3 lib/puppet/provider/confine/variable.rb
puppet-3.2.3.rc1 lib/puppet/provider/confine/variable.rb
puppet-3.2.2 lib/puppet/provider/confine/variable.rb