Sha256: e9260d16b01daf5b9c41628ddada8ab11ebe9628eb0cd12e48bcfa369c774769

Contents?: true

Size: 1.67 KB

Versions: 20

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

# The class that handles testing whether our providers
# actually work or not.
require_relative '../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.include?(name)
      begin
        require "puppet/confine/#{name}"
      rescue LoadError => detail
        unless detail.to_s =~ /No such file|cannot load such file/i
          Puppet.warning("Could not load confine test '#{name}': #{detail}")
        end
        # Could not find file
        unless Puppet[:always_retry_plugins]
          @tests[name] = nil
        end
      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

    true
  ensure
    reset
  end

  # Provide a hook for subclasses.
  def reset
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/confine.rb
puppet-8.10.0-x86-mingw32 lib/puppet/confine.rb
puppet-8.10.0-x64-mingw32 lib/puppet/confine.rb
puppet-8.10.0-universal-darwin lib/puppet/confine.rb
puppet-8.9.0 lib/puppet/confine.rb
puppet-8.9.0-x86-mingw32 lib/puppet/confine.rb
puppet-8.9.0-x64-mingw32 lib/puppet/confine.rb
puppet-8.9.0-universal-darwin lib/puppet/confine.rb
puppet-8.8.1 lib/puppet/confine.rb
puppet-8.8.1-x86-mingw32 lib/puppet/confine.rb
puppet-8.8.1-x64-mingw32 lib/puppet/confine.rb
puppet-8.8.1-universal-darwin lib/puppet/confine.rb
puppet-8.7.0 lib/puppet/confine.rb
puppet-8.7.0-x86-mingw32 lib/puppet/confine.rb
puppet-8.7.0-x64-mingw32 lib/puppet/confine.rb
puppet-8.7.0-universal-darwin lib/puppet/confine.rb
puppet-8.6.0 lib/puppet/confine.rb
puppet-8.6.0-x86-mingw32 lib/puppet/confine.rb
puppet-8.6.0-x64-mingw32 lib/puppet/confine.rb
puppet-8.6.0-universal-darwin lib/puppet/confine.rb