Class: Facter::Util::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/util/loader.rb

Overview

Load facts on demand.

Instance Method Summary collapse

Instance Method Details

#load(fact) ⇒ Object

Load all resolutions for a single fact.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/facter/util/loader.rb', line 6

def load(fact)
    # Now load from the search path
    shortname = fact.to_s.downcase
    load_env(shortname)

    filename = shortname + ".rb"
    search_path.each do |dir|
        # Load individual files
        file = File.join(dir, filename)

        load_file(file) if FileTest.exist?(file)

        # And load any directories matching the name
        factdir = File.join(dir, shortname)
        load_dir(factdir) if FileTest.directory?(factdir)
    end
end

#load_allObject

Load all facts from all directories.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/facter/util/loader.rb', line 25

def load_all
    return if defined?(@loaded_all)

    load_env

    search_path.each do |dir|
        next unless FileTest.directory?(dir)

        Dir.entries(dir).sort.each do |file|
            path = File.join(dir, file)
            if File.directory?(path)
                load_dir(path)
            elsif file =~ /\.rb$/
                load_file(File.join(dir, file))
            end
        end
    end

    @loaded_all = true
end

#search_pathObject

The list of directories we're going to search through for facts.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/facter/util/loader.rb', line 47

def search_path
    result = []
    result += $LOAD_PATH.collect { |d| File.join(d, "facter") }
    if ENV.include?("FACTERLIB")
        result += ENV["FACTERLIB"].split(":")
    end

    # This allows others to register additional paths we should search.
    result += Facter.search_path

    result
end