Module: Facter

### Home Classes Methods

### In Files

- lib/facter/util/nothing_loader.rb
- lib/facter/util/file_read.rb
- lib/facter/util/values.rb
- lib/facter/util/processor.rb
- lib/facter/util/solaris_zones.rb
- lib/facter/util/monkey_patches.rb
- lib/facter/version.rb
- lib/facter/application.rb
- lib/facter.rb

### Namespace

- MODULE Facter::Application
- MODULE Facter::Manufacturer
- MODULE Facter::Memory
- MODULE Facter::NetMask
- MODULE Facter::Util

### Methods

- ::[]
- ::add
- ::clear
- ::clear_messages
- ::collection
- ::debug
- ::debugging
- ::debugging?
- ::debugonce
- ::each
- ::json?
- ::loadfacts
- ::method_missing
- ::reset
- ::search
- ::search_path
- ::show_time
- ::timing
- ::timing?
- ::version
- ::version=
- ::warn
- ::warnonce

### Included Modules

- Comparable
- Enumerable

### Files

- LICENSE
- Rakefile
- THANKS

### Class/Module Index

Quicksearch

- Facter
- Facter::Application
- Facter::Manufacturer
- Facter::Memory
- Facter::NetMask
- Facter::Util
- Facter::Util::CFPropertyList
- Facter::Util::CFPropertyList::CFArray
- Facter::Util::CFPropertyList::CFBoolean
- Facter::Util::CFPropertyList::CFData
- Facter::Util::CFPropertyList::CFDate
- Facter::Util::CFPropertyList::CFDictionary
- Facter::Util::CFPropertyList::CFInteger
- Facter::Util::CFPropertyList::CFReal
- Facter::Util::CFPropertyList::CFString
- Facter::Util::CFPropertyList::CFType
- Facter::Util::CFPropertyList::XML
- Facter::Util::Collection
- Facter::Util::CompositeLoader
- Facter::Util::Config
- Facter::Util::Confine
- Facter::Util::DirectoryLoader
- Facter::Util::DirectoryLoader::NoSuchDirectoryError
- Facter::Util::EC2
- Facter::Util::Fact
- Facter::Util::FileRead
- Facter::Util::IP
- Facter::Util::IP::Windows
- Facter::Util::IP::Windows::Bindings4
- Facter::Util::IP::Windows::Bindings6
- Facter::Util::Loader
- Facter::Util::Macaddress
- Facter::Util::Macaddress::Darwin
- Facter::Util::Macaddress::Windows
- Facter::Util::Macosx
- Facter::Util::MonkeyPatches
- Facter::Util::MonkeyPatches::Lines
- Facter::Util::NothingLoader
- Facter::Util::Parser
- Facter::Util::Parser::Base
- Facter::Util::Parser::JsonParser
- Facter::Util::Parser::KeyValuePairOutputFormat
- Facter::Util::Parser::NothingParser
- Facter::Util::Parser::PowershellParser
- Facter::Util::Parser::ScriptParser
- Facter::Util::Parser::TextParser
- Facter::Util::Parser::YamlParser
- Facter::Util::Processor
- Facter::Util::Registry
- Facter::Util::Resolution
- Facter::Util::SolarisZones
- Facter::Util::Uptime
- Facter::Util::Values
- Facter::Util::Virtual
- Facter::Util::Vlans
- Facter::Util::WMI
- Facter::Util::Xendomains
- Plist
- Plist::Emit
- Plist::Listener
- Plist::PArray
- Plist::PData
- Plist::PDate
- Plist::PDict
- Plist::PFalse
- Plist::PInteger
- Plist::PKey
- Plist::PList
- Plist::PReal
- Plist::PString
- Plist::PTag
- Plist::PTrue
- Plist::StreamParser
- CFFormatError
- CFPlistError
- CFTypeError
- IO
- Object
- String

No matching classes.

# Facter

This makes it possible to disable loading of external facts

A util module for facter containing helper methods

### Constants

FACTERVERSION
GREEN

  ## Synopsis

  Generally, treat `Facter` as a hash:

  ## Example

  require 'facter' puts Facter

RESET

### 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 105
    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 127
    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 172
    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 179
    def self.clear_messages
      @@messages.clear
    end

collection() click to toggle source

module methods

    # File lib/facter.rb, line 52
    def self.collection
      unless defined?(@collection) and @collection
        @collection = Facter::Util::Collection.new(
          Facter::Util::Loader.new,
          Facter::Util::Config.ext_fact_loader)
      end
      @collection
    end

debug(string) click to toggle source

Add some debugging

    # File lib/facter.rb, line 62
    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 184
    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 79
    def self.debugging?
      @@debug != 0
    end

debugonce(msg) click to toggle source

Debug once.

    # File lib/facter.rb, line 72
    def self.debugonce(msg)
      if msg and not msg.empty? and @@debug_messages[msg].nil?
        @@debug_messages[msg] = true
        debug(msg)
      end
    end

each() click to toggle source

    # File lib/facter.rb, line 131
    def self.each
      # Make sure all facts are loaded.
      collection.load_all

      collection.each do |*args|
        yield(*args)
      end
    end

json?() click to toggle source

Facter.json? is meant to provide a lightweight way to check if the JSON "feature" is available.

    # File lib/facter.rb, line 94
    def self.json?
      begin
        require 'json'
        true
      rescue LoadError
        false
      end
    end

loadfacts() click to toggle source

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

    # File lib/facter.rb, line 247
    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 143
    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 242
    def self.reset
      @collection = nil
    end

search(*dirs) click to toggle source

Register a directory to search through.

    # File lib/facter.rb, line 254
    def self.search(*dirs)
      @search_path += dirs
    end

search_path() click to toggle source

Return our registered search directories.

    # File lib/facter.rb, line 259
    def self.search_path
      @search_path.dup
    end

show_time(string) click to toggle source

show the timing information

    # File lib/facter.rb, line 84
    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 210
    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 88
    def self.timing?
      @@timing != 0
    end

version() click to toggle source

version is a public API method intended to always provide a fast and lightweight way to determine the version of Facter.

The intent is that software external to Facter be able to determine the Facter version with no side-effects. The expected use is:

    require 'facter/version'
    version = Facter.version

This function has the following ordering precedence. This precedence list is designed to facilitate automated packaging tasks by simply writing to the VERSION file in the same directory as this source file.

    1. If a version has been explicitly assigned using the Facter.version=
       method, return that version.
    2. If there is a VERSION file, read the contents, trim any
       trailing whitespace, and return that version string.
    3. Return the value of the Facter::FACTERVERSION constant hard-coded into
       the source code.

If there is no VERSION file, the method must return the version string of the nearest parent version that is an officially released version. That is to say, if a branch named 3.1.x contains 25 patches on top of the most recent official release of 3.1.1, then the version method must return the string "3.1.1" if no "VERSION" file is present.

By design the version identifier is not intended to vary during the life a process. There is no guarantee provided that writing to the VERSION file while a Puppet process is running will cause the version string to be updated. On the contrary, the contents of the VERSION are cached to reduce filesystem accesses.

The VERSION file is intended to be used by package maintainers who may be applying patches or otherwise changing the software version in a manner that warrants a different software version identifier. The VERSION file is intended to be managed and owned by the release process and packaging related tasks, and as such should not reside in version control. The FACTERVERSION constant is intended to be version controlled in history.

Ideally, this behavior will allow package maintainers to precisely specify the version of the software they're packaging as in the following example:

    $ git describe > lib/facter/VERSION
    $ ruby -r facter -e 'puts Facter.version'
    1.6.14-6-g66f2c99

@api public

@return [String] containing the facter version, e.g. "1.6.14"

    # File lib/facter/version.rb, line 56
    def self.version
      version_file = File.join(File.dirname(__FILE__), 'VERSION')
      return @facter_version if @facter_version
      if version = read_version_file(version_file)
        @facter_version = version
      end
      @facter_version ||= FACTERVERSION
    end

version=(version) click to toggle source

    # File lib/facter/version.rb, line 65
    def self.version=(version)
      @facter_version = version
    end

warn(msg) click to toggle source

    # File lib/facter.rb, line 226
    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 234
    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.