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

Methods

exec   length   new   suitable?   tag   to_s   value  

Attributes

code  [RW] 
interpreter  [RW] 
name  [RW] 

Public Class methods

[Source]

     # File lib/facter.rb, line 311
311:         def Resolution.exec(code, interpreter = "/bin/sh")
312:             if interpreter == "/bin/sh"
313:                 binary = code.split(/\s+/).shift
314: 
315:                 path = nil
316:                 if binary !~ /^\//
317:                     path = %x{which #{binary} 2>/dev/null}.chomp
318:                     if path == ""
319:                         # we don't have the binary necessary
320:                         return nil
321:                     end
322:                 else
323:                     path = binary
324:                 end
325: 
326:                 unless FileTest.exists?(path)
327:                     # our binary does not exist
328:                     return nil
329:                 end
330:                 out = nil
331:                 begin
332:                     out = %x{#{code}}.chomp
333:                 rescue => detail
334:                     $stderr.puts detail
335:                     return nil
336:                 end
337:                 if out == ""
338:                     return nil
339:                 else
340:                     return out
341:                 end
342:             else
343:                 raise "non-sh interpreters are not currently supported"
344:             end
345:         end

[Source]

     # File lib/facter.rb, line 347
347:         def initialize(name)
348:             @name = name
349:             @tags = []
350:         end

Public Instance methods

[Source]

     # File lib/facter.rb, line 352
352:         def length
353:             @tags.length
354:         end

[Source]

     # File lib/facter.rb, line 356
356:         def suitable?
357:             unless defined? @suitable
358:                 @suitable = true
359:                 if @tags.length == 0
360:                     #Facter.debug "'%s' has no tags" % @name
361:                     return true
362:                 end
363:                 @tags.each { |tag|
364:                     unless tag.true?
365:                         #Facter.debug "'%s' is false" % tag
366:                         @suitable = false
367:                     end
368:                 }
369:             end
370: 
371:             return @suitable
372:         end

[Source]

     # File lib/facter.rb, line 374
374:         def tag(fact,op,value)
375:             @tags.push Tag.new(fact,op,value)
376:         end

[Source]

     # File lib/facter.rb, line 378
378:         def to_s
379:             return self.value()
380:         end

how we get a value for our resolution mechanism

[Source]

     # File lib/facter.rb, line 383
383:         def value
384:             #puts "called %s value" % @name
385:             value = nil
386:             if @code.is_a?(Proc)
387:                 value = @code.call()
388:             else
389:                 unless defined? @interpreter
390:                     @interpreter = "/bin/sh"
391:                 end
392:                 if @code.nil?
393:                     $stderr.puts "Code for %s is nil" % @name
394:                 else
395:                     value = Resolution.exec(@code,@interpreter)
396:                 end
397:             end
398: 
399:             if value == ""
400:                 value = nil
401:             end
402: 
403:             return value
404:         end

[Validate]