class Facter::Util::Loader
Load facts on demand.
Public Class Methods
new(environment_vars = ENV)
click to toggle source
# File lib/facter/util/loader.rb, line 8 def initialize(environment_vars = ENV) @loaded = [] @environment_vars = environment_vars end
Public Instance Methods
load(fact)
click to toggle source
Load all resolutions for a single fact.
@api public @param name [Symbol]
# File lib/facter/util/loader.rb, line 17 def load(fact) # Now load from the search path shortname = fact.to_s.downcase load_env(shortname) filename = shortname + ".rb" paths = search_path unless paths.nil? paths.each do |dir| # Load individual files file = File.join(dir, filename) load_file(file) if File.file?(file) end end end
load_all()
click to toggle source
Load all facts from all directories.
@api public
# File lib/facter/util/loader.rb, line 38 def load_all return if defined?(@loaded_all) load_env paths = search_path unless paths.nil? paths.each do |dir| # dir is already an absolute path Dir.glob(File.join(dir, '*.rb')).each do |path| # exclude dirs that end with .rb load_file(path) if File.file?(path) end end end @loaded_all = true end
search_path()
click to toggle source
List directories to search for fact files.
Search paths are gathered from the following sources:
-
$LOAD_PATH entries are expanded to absolute paths
-
ENV is split and used verbatim
-
Entries from Facter.search_path are used verbatim
A warning will be generated for paths in Facter.search_path that are not absolute directories.
@api public @return [Array<String>]
# File lib/facter/util/loader.rb, line 70 def search_path search_paths = [] search_paths += $LOAD_PATH.map { |path| File.expand_path('facter', path) } if @environment_vars.include?("FACTERLIB") search_paths += @environment_vars["FACTERLIB"].split(File::PATH_SEPARATOR) end search_paths.delete_if { |path| ! valid_search_path?(path) } Facter.search_path.each do |path| if valid_search_path?(path) search_paths << path else Facter.warn "Excluding #{path} from search path. Fact file paths must be an absolute directory" end end search_paths.delete_if { |path| ! File.directory?(path) } search_paths.uniq end