Class: Facter::Util::Fact

### Home Classes Methods

### In Files

- lib/facter/util/fact.rb

### Parent

Object

### Methods

- ::new
- #add
- #flush
- #value

### 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::Util::Fact

### Constants

TIMEOUT

### Attributes

ldapname[RW]
name[RW]

### Public Class Methods

new(name, options = {}) click to toggle source

Create a new fact, with no resolution mechanisms.

    # File lib/facter/util/fact.rb, line 10
    def initialize(name, options = {})
      @name = name.to_s.downcase.intern

      # LAK:NOTE: This is slow for many options, but generally we won't have any and at
      # worst we'll have one.  If we add more, this should be made more efficient.
      options.each do |name, value|
        case name
        when :ldapname; self.ldapname = value
        else
          raise ArgumentError, "Invalid fact option '%s'" % name
        end
      end

      @ldapname ||= @name.to_s

      @resolves = []
      @searching = false

      @value = nil
    end

### Public Instance Methods

add(value = nil, &block) click to toggle source

Add a new resolution mechanism. This requires a block, which will then be evaluated in the context of the new mechanism.

    # File lib/facter/util/fact.rb, line 33
    def add(value = nil, &block)
      begin
        resolve = Facter::Util::Resolution.new(@name)

        resolve.instance_eval(&block) if block
        @resolves << resolve

        resolve
      rescue => e
        Facter.warn "Unable to add resolve for #{@name}: #{e}"
        nil
      end
    end

flush() click to toggle source

Flush any cached values. If the resolver has a callback block defined using the on_flush DSL method, then invoke that block by sending a message to Resolution#flush.

    # File lib/facter/util/fact.rb, line 51
    def flush
      @resolves.each { |r| r.flush }
      @value = nil
    end

value() click to toggle source

Return the value for a given fact. Searches through all of the mechanisms and returns either the first value or nil.

    # File lib/facter/util/fact.rb, line 58
    def value
      return @value if @value

      if @resolves.empty?
        Facter.debug "No resolves for %s" % @name
        return nil
      end

      searching do

        suitable_resolutions = sort_by_weight(find_suitable_resolutions(@resolves))
        @value = find_first_real_value(suitable_resolutions)

        announce_when_no_suitable_resolution(suitable_resolutions)
        announce_when_no_value_found(@value)

        @value
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.