Class Facter::Util::Loader
In: lib/facter/util/loader.rb
Parent: Object

Load facts on demand.

Methods

load   load_all   search_path  

Public Instance methods

Load all resolutions for a single fact.

[Source]

    # File lib/facter/util/loader.rb, line 6
 6:     def load(fact)
 7:         # Now load from the search path
 8:         shortname = fact.to_s.downcase
 9:         load_env(shortname)
10: 
11:         filename = shortname + ".rb"
12:         search_path.each do |dir|
13:             # Load individual files
14:             file = File.join(dir, filename)
15: 
16:             load_file(file) if FileTest.exist?(file)
17: 
18:             # And load any directories matching the name
19:             factdir = File.join(dir, shortname)
20:             load_dir(factdir) if FileTest.directory?(factdir)
21:         end
22:     end

Load all facts from all directories.

[Source]

    # File lib/facter/util/loader.rb, line 25
25:     def load_all
26:         return if defined?(@loaded_all)
27: 
28:         load_env
29: 
30:         search_path.each do |dir|
31:             next unless FileTest.directory?(dir)
32: 
33:             Dir.entries(dir).each do |file|
34:                 path = File.join(dir, file)
35:                 if File.directory?(path)
36:                     load_dir(path)
37:                 elsif file =~ /\.rb$/
38:                     load_file(File.join(dir, file))
39:                 end
40:             end
41:         end
42: 
43:         @loaded_all = true
44:     end

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

[Source]

    # File lib/facter/util/loader.rb, line 47
47:     def search_path
48:         result = []
49:         result += $LOAD_PATH.collect { |d| File.join(d, "facter") }
50:         if ENV.include?("FACTERLIB")
51:             result += ENV["FACTERLIB"].split(":")
52:         end
53: 
54:         # This allows others to register additional paths we should search.
55:         result += Facter.search_path
56: 
57:         result
58:     end

[Validate]