Class Facter::Confine
In: lib/facter.rb
Parent: Object

A restricting tag for fact resolution mechanisms. The tag must be true for the resolution mechanism to be suitable.

Methods

new   to_s   true?  

Attributes

fact  [RW] 
op  [RW] 
value  [RW] 

Public Class methods

Add the tag. Requires the fact name, an operator, and the value we‘re comparing to.

[Source]

     # File lib/facter.rb, line 538
538:         def initialize(fact, *values)
539:             fact = fact.to_s if fact.is_a? Symbol
540:             @fact = fact
541:             @values = values.collect do |value|
542:                 if value.is_a? String
543:                     value
544:                 else
545:                     value.to_s
546:                 end
547:             end
548:         end

Public Instance methods

[Source]

     # File lib/facter.rb, line 550
550:         def to_s
551:             return "'%s' '%s'" % [@fact, @values.join(",")]
552:         end

Evaluate the fact, returning true or false.

[Source]

     # File lib/facter.rb, line 555
555:         def true?
556:             fact = nil
557:             unless fact = Facter[@fact]
558:                 Facter.debug "No fact for %s" % @fact
559:                 return false
560:             end
561:             value = fact.value
562: 
563:             if value.nil?
564:                 return false
565:             end
566: 
567:             retval = @values.find { |v|
568:                 if value.downcase == v.downcase
569:                     break true
570:                 end
571:             }
572: 
573:             if retval
574:                 retval = true
575:             else
576:                 retval = false
577:             end
578: 
579:             return retval || false
580:         end

[Validate]