Sha256: 4ff653734b5f4f841fa5f6a2ccc59e9326cbb28cc6bcbbe8e92b692d8e7ff6ba

Contents?: true

Size: 1.53 KB

Versions: 314

Compression:

Stored size: 1.53 KB

Contents

# The class that handles testing whether our providers
# actually work or not.
require 'puppet/util'

class Puppet::Confine
  include Puppet::Util

  @tests = {}

  class << self
    attr_accessor :name
  end

  def self.inherited(klass)
    name = klass.to_s.split("::").pop.downcase.to_sym
    raise "Test #{name} is already defined" if @tests.include?(name)

    klass.name = name

    @tests[name] = klass
  end

  def self.test(name)
    unless @tests[name]
      begin
        require "puppet/confine/#{name}"
      rescue LoadError => detail
        unless detail.to_s =~ /No such file|cannot load such file/i
          warn "Could not load confine test '#{name}': #{detail}"
        end
        # Could not find file
      end
    end
    @tests[name]
  end

  attr_reader :values

  # Mark that this confine is used for testing binary existence.
  attr_accessor :for_binary
  def for_binary?
    for_binary
  end

  # Used for logging.
  attr_accessor :label

  def initialize(values)
    values = [values] unless values.is_a?(Array)
    @values = values
  end

  # Provide a hook for the message when there's a failure.
  def message(value)
    ""
  end

  # Collect the results of all of them.
  def result
    values.collect { |value| pass?(value) }
  end

  # Test whether our confine matches.
  def valid?
    values.each do |value|
      unless pass?(value)
        Puppet.debug(label + ": " + message(value))
        return false
      end
    end

    return true
  ensure
    reset
  end

  # Provide a hook for subclasses.
  def reset
  end
end

Version data entries

314 entries across 314 versions & 3 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/confine.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/confine.rb
puppet-5.3.7 lib/puppet/confine.rb
puppet-5.3.7-x86-mingw32 lib/puppet/confine.rb
puppet-5.3.7-x64-mingw32 lib/puppet/confine.rb
puppet-5.3.7-universal-darwin lib/puppet/confine.rb
puppet-4.10.12 lib/puppet/confine.rb
puppet-4.10.12-x86-mingw32 lib/puppet/confine.rb
puppet-4.10.12-x64-mingw32 lib/puppet/confine.rb
puppet-4.10.12-universal-darwin lib/puppet/confine.rb
bolt-0.20.3 vendored/puppet/lib/puppet/confine.rb
bolt-0.20.2 vendored/puppet/lib/puppet/confine.rb
bolt-0.19.1 vendored/puppet/lib/puppet/confine.rb
puppet-4.10.11 lib/puppet/confine.rb
puppet-4.10.11-x86-mingw32 lib/puppet/confine.rb
puppet-4.10.11-x64-mingw32 lib/puppet/confine.rb
puppet-4.10.11-universal-darwin lib/puppet/confine.rb
puppet-5.3.6 lib/puppet/confine.rb
puppet-5.3.6-x86-mingw32 lib/puppet/confine.rb
puppet-5.3.6-x64-mingw32 lib/puppet/confine.rb