class Facter::Util::Confine

Attributes

fact[RW]
values[RW]

Public Instance Methods

to_s() click to toggle source
# File lib/facter/util/confine.rb, line 20
def to_s
  return "'%s' '%s'" % [@fact, @values.join(",")]
end
true?() click to toggle source

Evaluate the fact, returning true or false.

# File lib/facter/util/confine.rb, line 25
def true?
  unless fact = Facter[@fact]
    Facter.debug "No fact for %s" % @fact
    return false
  end
  value = convert(fact.value)

  return false if value.nil?

  @values.each do |v|
    v = convert(v)
    next unless v.class == value.class
    return true if value == v
  end
  return false
end

Public Class Methods

new(fact, *values) click to toggle source

Add the restriction. Requires the fact name, an operator, and the value we’re comparing to.

# File lib/facter/util/confine.rb, line 13
def initialize(fact, *values)
  raise ArgumentError, "The fact name must be provided" unless fact
  raise ArgumentError, "One or more values must be provided" if values.empty?
  @fact = fact
  @values = values
end