diff options
author | Luke Kanies <luke@madstop.com> | 2008-05-15 15:24:29 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-05-15 15:24:29 -0500 |
commit | f1acbc0403068141c80b74c8585a1629fd45711b (patch) | |
tree | 346894daf9bad2228e2f8396e1303048cdc43a3a /lib/facter.rb | |
parent | bb92493c3868c54ef441a4f60c0b6a95ff742f88 (diff) | |
download | facter-f1acbc0403068141c80b74c8585a1629fd45711b.tar.gz facter-f1acbc0403068141c80b74c8585a1629fd45711b.tar.xz facter-f1acbc0403068141c80b74c8585a1629fd45711b.zip |
Switching Facter to using the new loader.
This should make it possible to move all facts to separate
files and only load them on demand.
Diffstat (limited to 'lib/facter.rb')
-rw-r--r-- | lib/facter.rb | 62 |
1 files changed, 18 insertions, 44 deletions
diff --git a/lib/facter.rb b/lib/facter.rb index 0f00f7d..91588d3 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -77,11 +77,18 @@ module Facter end class << self - [:add, :each, :fact, :flush, :list, :to_hash, :value].each do |method| + [:add, :fact, :flush, :list, :value].each do |method| define_method(method) do |*args| collection.send(method, *args) end end + + [:list, :to_hash].each do |method| + define_method(method) do |*args| + collection.load_all + collection.send(method, *args) + end + end end @@ -91,6 +98,15 @@ module Facter collection.add(name, options, &block) end + def self.each + # Make sure all facts are loaded. + collection.load_all + + collection.each do |*args| + yield(*args) + end + end + class << self # Allow users to call fact names directly on the Facter class, # either retrieving the value or comparing it to an existing value. @@ -189,49 +205,7 @@ module Facter end end - locals = [] - - # Now find all our loadable facts - factdirs = [] # All the places to check for facts - - # See if we can find any other facts in the regular Ruby lib - # paths - $:.each do |dir| - fdir = File.join(dir, "facter") - if FileTest.exists?(fdir) and FileTest.directory?(fdir) - factdirs.push(fdir) - end - end - # Also check anything in 'FACTERLIB' - if ENV['FACTERLIB'] - ENV['FACTERLIB'].split(":").each do |fdir| - factdirs.push(fdir) - end - end - factdirs.each do |fdir| - Dir.glob("#{fdir}/*.rb").each do |file| - # Load here, rather than require, because otherwise - # the facts won't get reloaded if someone calls - # "loadfacts". Really only important in testing, but, - # well, it's important in testing. - begin - load file - rescue => detail - warn "Could not load %s: %s" % - [file, detail] - end - end - end - - - # Now try to get facts from the environment - ENV.each do |name, value| - if name =~ /^facter_?(\w+)$/i - Facter.add($1) do - setcode { value } - end - end - end + collection.load_all end Facter.loadfacts |