| Class | Facter::Util::Confine |
| In: |
lib/facter/util/confine.rb
|
| Parent: | Object |
A restricting tag for fact resolution mechanisms. The tag must be true for the resolution mechanism to be suitable.
| fact | [RW] | |
| values | [RW] |
Add the restriction. Requires the fact name, an operator, and the value we‘re comparing to.
# File lib/facter/util/confine.rb, line 8
8: def initialize(fact, *values)
9: raise ArgumentError, "The fact name must be provided" unless fact
10: raise ArgumentError, "One or more values must be provided" if values.empty?
11: fact = fact.to_s if fact.is_a? Symbol
12: @fact = fact
13: @values = values.collect do |value|
14: if value.is_a? String
15: value
16: else
17: value.to_s
18: end
19: end
20: end
# File lib/facter/util/confine.rb, line 22
22: def to_s
23: return "'%s' '%s'" % [@fact, @values.join(",")]
24: end
Evaluate the fact, returning true or false.
# File lib/facter/util/confine.rb, line 27
27: def true?
28: unless fact = Facter[@fact]
29: Facter.debug "No fact for %s" % @fact
30: return false
31: end
32: value = fact.value
33:
34: return false if value.nil?
35:
36: @values.each { |v|
37: return true if value.downcase == v.downcase
38: }
39: return false
40: end