Class: Facter::Util::Loader
- Inherits:
-
Object
- Object
- Facter::Util::Loader
- Defined in:
- lib/facter/util/loader.rb
Overview
Load facts on demand.
Instance Method Summary (collapse)
-
- (Object) load(fact)
Load all resolutions for a single fact.
-
- (Object) load_all
Load all facts from all directories.
-
- (Object) search_path
The list of directories we're going to search through for facts.
Instance Method Details
- (Object) load(fact)
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 |
- (Object) load_all
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 |
- (Object) search_path
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 |