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

    # File lib/puppet/provider/confine/variable.rb, line 24
    def initialize(values)
      super
      @values = @values.collect { |v| v.to_s.downcase }
    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/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

### Public Instance Methods

facter_value() click to toggle source

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

message(value) click to toggle source

    # 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

pass?(value) click to toggle source

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

reset() click to toggle source

    # 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

valid?() click to toggle source

    # File lib/puppet/provider/confine/variable.rb, line 44
    def valid?
      @values.include?(test_value.to_s.downcase)
    ensure
      reset
    end