Included Modules

Facter

A util module for facter containing helper methods

Public Class Methods

[](name) click to toggle source

Return a fact object by name. If you use this, you still have to call 'value' on it to retrieve the actual value.

# File lib/facter.rb, line 87
def self.[](name)
  collection.fact(name)
end
add(name, options = {}, &block) click to toggle source

Add a resolution mechanism for a named fact. This does not distinguish between adding a new fact and adding a new way to resolve a fact.

# File lib/facter.rb, line 109
def self.add(name, options = {}, &block)
  collection.add(name, options, &block)
end
clear() click to toggle source

Clear all facts. Mostly used for testing.

# File lib/facter.rb, line 154
def self.clear
  Facter.flush
  Facter.reset
end
clear_messages() click to toggle source

Clear all messages. Used only in testing. Can't add to self.clear because we don't want to warn multiple times for items that are warnonce'd

# File lib/facter.rb, line 161
def self.clear_messages
  @@messages.clear
end
collection() click to toggle source

module methods

# File lib/facter.rb, line 55
def self.collection
  unless defined?(@collection) and @collection
    @collection = Facter::Util::Collection.new
  end
  @collection
end
debug(string) click to toggle source

Add some debugging

# File lib/facter.rb, line 63
def self.debug(string)
  if string.nil?
    return
  end
  if self.debugging?
    puts GREEN + string + RESET
  end
end
debugging(bit) click to toggle source

Set debugging on or off.

# File lib/facter.rb, line 166
def self.debugging(bit)
  if bit
    case bit
    when TrueClass; @@debug = 1
    when FalseClass; @@debug = 0
    when Fixnum
      if bit > 0
        @@debug = 1
      else
        @@debug = 0
      end
    when String;
      if bit.downcase == 'off'
        @@debug = 0
      else
        @@debug = 1
      end
    else
      @@debug = 0
    end
  else
    @@debug = 0
  end
end
debugging?() click to toggle source
# File lib/facter.rb, line 72
def self.debugging?
  @@debug != 0
end
each() click to toggle source
# File lib/facter.rb, line 113
def self.each
  # Make sure all facts are loaded.
  collection.load_all

  collection.each do |*args|
    yield(*args)
  end
end
loadfacts() click to toggle source

Load all of the default facts, and then everything from disk.

# File lib/facter.rb, line 229
def self.loadfacts
  collection.load_all
end
method_missing(name, *args) click to toggle source

Allow users to call fact names directly on the Facter class, either retrieving the value or comparing it to an existing value.

# File lib/facter.rb, line 125
def method_missing(name, *args)
  question = false
  if name.to_s =~ /\?$/
    question = true
    name = name.to_s.sub(/\?$/,'')
  end

  if fact = collection.fact(name)
    if question
      value = fact.value.downcase
      args.each do |arg|
        if arg.to_s.downcase == value
          return true
        end
      end

      # If we got this far, there was no match.
      return false
    else
      return fact.value
    end
  else
    # Else, fail like a normal missing method.
    raise NoMethodError, "Could not find fact '%s'" % name
  end
end
reset() click to toggle source

Remove them all.

# File lib/facter.rb, line 224
def self.reset
  @collection = nil
end
search(*dirs) click to toggle source

Register a directory to search through.

# File lib/facter.rb, line 236
def self.search(*dirs)
  @search_path += dirs
end
search_path() click to toggle source

Return our registered search directories.

# File lib/facter.rb, line 241
def self.search_path
  @search_path.dup
end
show_time(string) click to toggle source

show the timing information

# File lib/facter.rb, line 77
def self.show_time(string)
  puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing?
end
timing(bit) click to toggle source

Set timing on or off.

# File lib/facter.rb, line 192
def self.timing(bit)
  if bit
    case bit
    when TrueClass; @@timing = 1
    when Fixnum
      if bit > 0
        @@timing = 1
      else
        @@timing = 0
      end
    end
  else
    @@timing = 0
  end
end
timing?() click to toggle source
# File lib/facter.rb, line 81
def self.timing?
  @@timing != 0
end
version() click to toggle source
# File lib/facter/version.rb, line 6
def self.version
  @facter_version || FACTERVERSION
end
version=(version) click to toggle source
# File lib/facter/version.rb, line 10
def self.version=(version)
  @facter_version = version
end
warn(msg) click to toggle source
# File lib/facter.rb, line 208
def self.warn(msg)
  if Facter.debugging? and msg and not msg.empty?
    msg = [msg] unless msg.respond_to? :each
    msg.each { |line| Kernel.warn line }
  end
end
warnonce(msg) click to toggle source

Warn once.

# File lib/facter.rb, line 216
def self.warnonce(msg)
  if msg and not msg.empty? and @@messages[msg].nil?
    @@messages[msg] = true
    Kernel.warn(msg)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.