diff options
author | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-05-30 22:54:26 +0000 |
---|---|---|
committer | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-05-30 22:54:26 +0000 |
commit | 01d37d94e8588a7a9dad7311c8b1eeafaf82c7b5 (patch) | |
tree | 652e2ee41c0afabebb25c89996f1c0581b6d47c9 | |
parent | 3a0181ebadc8f8cfe9cac7591971cd5fde23c8e5 (diff) | |
download | facter-01d37d94e8588a7a9dad7311c8b1eeafaf82c7b5.tar.gz facter-01d37d94e8588a7a9dad7311c8b1eeafaf82c7b5.tar.xz facter-01d37d94e8588a7a9dad7311c8b1eeafaf82c7b5.zip |
Getting rid of the autoload method entirely; facts are now only loaded at startup.
git-svn-id: http://reductivelabs.com/svn/facter/trunk@116 1f5c1d6a-bddf-0310-8f58-fc49e503516a
-rw-r--r-- | lib/facter.rb | 23 | ||||
-rw-r--r-- | tests/tc_simple.rb | 44 |
2 files changed, 14 insertions, 53 deletions
diff --git a/lib/facter.rb b/lib/facter.rb index e7681ae..ce99ba7 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -56,9 +56,6 @@ class Facter # 'value' on it to retrieve the actual value. def Facter.[](name) name = name.to_s.downcase - unless @@facts.include?(name) - Facter.autoload(name) - end @@facts[name] end @@ -110,16 +107,6 @@ class Facter end end - # Load a file by path - def Facter.autoload(name) - begin - require "facter/#{name}" - rescue LoadError => detail - #warn "Failed to load %s: %s" % [name, detail] - # nothing, just ignore it, i guess - end - end - # Clear all facts. Mostly used for testing. def Facter.clear Facter.reset @@ -508,7 +495,7 @@ class Facter end # Load all of the default facts - def Facter.load + def Facter.loadfacts Facter.add("FacterVersion") do setcode { FACTERVERSION.to_s } end @@ -853,11 +840,15 @@ class Facter fdir = File.join(dir, "facter") if FileTest.exists?(fdir) and FileTest.directory?(fdir) Dir.glob("#{fdir}/*.rb").each do |file| - Facter.autoload(File.basename(file, '.rb')) + # 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. + load file end end end end - Facter.load + Facter.loadfacts end diff --git a/tests/tc_simple.rb b/tests/tc_simple.rb index 2d3c5fe..8efdbd7 100644 --- a/tests/tc_simple.rb +++ b/tests/tc_simple.rb @@ -16,7 +16,7 @@ end class TestFacter < Test::Unit::TestCase def setup - Facter.load + Facter.loadfacts @tmpfiles = [] end @@ -295,38 +295,6 @@ class TestFacter < Test::Unit::TestCase assert_raise(NoMethodError) { Facter.nosuchfact } end - # Verify we can autoload facts. - def test_autoloading - dir = "/tmp/facterloading" - @tmpfiles << dir - Dir.mkdir(dir) - Dir.mkdir(File.join(dir, "facter")) - $: << dir - - # Make sure we don't have a value right now. - assert_raise(NoMethodError) do - Facter.autoloadfact - end - assert_nil(Facter["autoloadfact"]) - - val = "autoloadedness" - File.open(File.join(dir, "facter", "autoloadfact.rb"), "w") do |file| - file.puts %{ -Facter.add("AutoloadFact") do - setcode { "#{val}" } -end -} - end - - ret = nil - assert_nothing_raised do - ret = Facter.autoloadfact - end - assert_equal(val, ret, "Got incorrect value for autoloaded fact") - assert_equal(val, Facter["autoloadfact"].value, - "Got incorrect value for autoloaded fact") - end - def test_versionfacts assert_nothing_raised { assert(Facter.facterversion, "Could not get facter version") @@ -364,7 +332,7 @@ end # And load assert_nothing_raised { - Facter.load + Facter.loadfacts } hash = nil @@ -405,7 +373,7 @@ end # And load assert_nothing_raised { - Facter.load + Facter.loadfacts } hash = nil @@ -432,13 +400,15 @@ some random stuff end assert_nothing_raised do - Facter.load + Facter.loadfacts end end if Facter.kernel == "Linux" def test_memoryonlinux - assert(Facter.memorysize, "Did not get memory") + assert_nothing_raised { + assert(Facter.memorysize, "Did not get memory") + } end end end |