diff options
author | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-05-30 22:12:04 +0000 |
---|---|---|
committer | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-05-30 22:12:04 +0000 |
commit | 165a401f2bf72c501815523be988be73f8d57f4e (patch) | |
tree | 20eafa729f071d0d4afc901ac62ca949780e115f | |
parent | af062c60304468beeff110e3f4297a312059b462 (diff) | |
download | facter-165a401f2bf72c501815523be988be73f8d57f4e.tar.gz facter-165a401f2bf72c501815523be988be73f8d57f4e.tar.xz facter-165a401f2bf72c501815523be988be73f8d57f4e.zip |
Accepting the patch in #9, with some modifications.
git-svn-id: http://reductivelabs.com/svn/facter/trunk@113 1f5c1d6a-bddf-0310-8f58-fc49e503516a
-rw-r--r-- | lib/facter.rb | 45 | ||||
-rwxr-xr-x | tests/tc_facterbin.rb | 3 | ||||
-rw-r--r-- | tests/tc_simple.rb | 3 |
3 files changed, 19 insertions, 32 deletions
diff --git a/lib/facter.rb b/lib/facter.rb index 3d3b807..e7681ae 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -11,7 +11,7 @@ class Facter include Comparable include Enumerable -FACTERVERSION = '1.2.1' + FACTERVERSION = '1.2.1' # = Facter 1.0 # Functions as a hash of 'facts' you might care about about your # system, such as mac address, IP address, Video card, etc. @@ -54,18 +54,10 @@ FACTERVERSION = '1.2.1' # Return a fact object by name. If you use this, you still have to call # 'value' on it to retrieve the actual value. - def Facter.[](name) + def Facter.[](name) name = name.to_s.downcase unless @@facts.include?(name) - # Try autoloading the fact. - begin - require "facter/#{name}" - unless @@facts.include?(name) - warn "Loaded facter/#{name} but fact was not added" - end - rescue LoadError - # Just ignore it - end + Facter.autoload(name) end @@facts[name] end @@ -107,24 +99,24 @@ FACTERVERSION = '1.2.1' end def method_missing(name, *args) + retval = nil if fact = self[name] - return fact.value + retval = fact.value else - super + retval = super end + + retval end end # Load a file by path - def Facter.autoload(file) - name = File.basename(file).sub(".rb",'') + def Facter.autoload(name) begin - require file - unless @@facts.include?(name) - warn "Loaded %s but it did not define fact %s" % [file, name] - end + require "facter/#{name}" rescue LoadError => detail - warn "Failed to load %s: %s" % [file, detail] + #warn "Failed to load %s: %s" % [name, detail] + # nothing, just ignore it, i guess end end @@ -860,17 +852,8 @@ FACTERVERSION = '1.2.1' $:.each do |dir| fdir = File.join(dir, "facter") if FileTest.exists?(fdir) and FileTest.directory?(fdir) - Dir.chdir(fdir) do - Dir.glob("*.rb").each do |file| - if file == "local.rb" - # Just require it normally - require File.join(fdir, file) - else - # We assume it's a new fact to be - # autoloaded, so ask Facter to load it for us - Facter.autoload(File.join(fdir, file)) - end - end + Dir.glob("#{fdir}/*.rb").each do |file| + Facter.autoload(File.basename(file, '.rb')) end end end diff --git a/tests/tc_facterbin.rb b/tests/tc_facterbin.rb index ce66855..e337b63 100755 --- a/tests/tc_facterbin.rb +++ b/tests/tc_facterbin.rb @@ -1,6 +1,9 @@ #! /usr/bin/env ruby $facterbase = File.dirname(File.dirname(__FILE__)) +if $facterbase == "." + $facterbase = ".." +end libdir = File.join($facterbase, "lib") $:.unshift libdir diff --git a/tests/tc_simple.rb b/tests/tc_simple.rb index 8f1819d..bd71c6d 100644 --- a/tests/tc_simple.rb +++ b/tests/tc_simple.rb @@ -88,8 +88,9 @@ class TestFacter < Test::Unit::TestCase assert_equal(nil, Facter["testing"].value) end - # I have no idea why this test is continually failing... def test_recursivetags + # This will try to autoload "required", which will fail, so the + # fact will be marked as unsuitable. assert_nothing_raised { Facter.add("testing") { setcode { "bar" } |