diff options
author | Luke Kanies <luke@madstop.com> | 2008-05-16 10:38:15 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-05-16 10:38:15 -0500 |
commit | bb41db0bf4221e394411d2a82b6de264b557fb95 (patch) | |
tree | fbc8773d5e6b5a708db24e3943ca3b3fb7f98880 | |
parent | 07a3d479b0e31aa7a1f8e6d0e178e440adc57030 (diff) | |
download | facter-bb41db0bf4221e394411d2a82b6de264b557fb95.tar.gz facter-bb41db0bf4221e394411d2a82b6de264b557fb95.tar.xz facter-bb41db0bf4221e394411d2a82b6de264b557fb95.zip |
Switching to a search path registration system.
Facter no longer knows anything about Puppet, so there's
no inter-dependency issue.
-rw-r--r-- | lib/facter.rb | 12 | ||||
-rw-r--r-- | lib/facter/util/loader.rb | 15 | ||||
-rwxr-xr-x | spec/integration/util/loader.rb | 26 | ||||
-rwxr-xr-x | spec/unit/facter.rb | 25 | ||||
-rwxr-xr-x | spec/unit/util/loader.rb | 7 |
5 files changed, 47 insertions, 38 deletions
diff --git a/lib/facter.rb b/lib/facter.rb index aae3326..525dbcd 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -179,4 +179,16 @@ module Facter def self.loadfacts collection.load_all end + + @search_path = [] + + # Register a directory to search through. + def self.search(*dirs) + @search_path += dirs + end + + # Return our registered search directories. + def self.search_path + @search_path.dup + end end diff --git a/lib/facter/util/loader.rb b/lib/facter/util/loader.rb index 44a0338..c6013cc 100644 --- a/lib/facter/util/loader.rb +++ b/lib/facter/util/loader.rb @@ -51,18 +51,9 @@ class Facter::Util::Loader result += ENV["FACTERLIB"].split(":") end - # LAK:NOTE We have to be this careful because facter gets loaded - # *very* early in Puppet's lifecycle, and this essentially - # builds interdependencies between the applications, which is - # tricky. - if defined?(Puppet) and Puppet.respond_to?(:settings) - if f = Puppet.settings.value(:factdest) - result << f - end - if l = Puppet.settings.value(:libdir) - result << File.join(l, "facter") - end - end + # This allows others to register additional paths we should search. + result += Facter.search_path + result end diff --git a/spec/integration/util/loader.rb b/spec/integration/util/loader.rb deleted file mode 100755 index af569cd..0000000 --- a/spec/integration/util/loader.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../../spec_helper' - -require 'facter/util/loader' - -begin - require 'puppet' -rescue LoadError - # Oh well, no Puppet :/ -end - -describe Facter::Util::Loader do - if defined?(Puppet) - describe "when the Puppet libraries are loaded" do - before { @loader = Facter::Util::Loader.new } - it "should include the factdest setting" do - @loader.search_path.should be_include(Puppet.settings.value(:factdest)) - end - - it "should include the facter subdirectory of the libdir setting" do - @loader.search_path.should be_include(File.join(Puppet.settings.value(:libdir), "facter")) - end - end - end -end diff --git a/spec/unit/facter.rb b/spec/unit/facter.rb index 59d10d4..18611aa 100755 --- a/spec/unit/facter.rb +++ b/spec/unit/facter.rb @@ -107,6 +107,31 @@ describe Facter do Facter.value(:macaddress).should_not be_include(" ") end + it "should have a method for registering directories to search" do + Facter.should respond_to(:search) + end + + it "should have a method for returning the registered search directories" do + Facter.should respond_to(:search_path) + end + + describe "when registering directories to search" do + after { Facter.instance_variable_set("@search_path", []) } + + it "should allow registration of a directory" do + Facter.search "/my/dir" + end + + it "should allow registration of multiple directories" do + Facter.search "/my/dir", "/other/dir" + end + + it "should return all registered directories when asked" do + Facter.search "/my/dir", "/other/dir" + Facter.search_path.should == %w{/my/dir /other/dir} + end + end + def test_onetrueconfine assert_nothing_raised { Facter.add("required") { diff --git a/spec/unit/util/loader.rb b/spec/unit/util/loader.rb index 5e25ef5..b9b4306 100755 --- a/spec/unit/util/loader.rb +++ b/spec/unit/util/loader.rb @@ -51,6 +51,13 @@ describe Facter::Util::Loader do end end + it "should include all search paths registered with Facter" do + Facter.expects(:search_path).returns %w{/one /two} + paths = @loader.search_path + paths.should be_include("/one") + paths.should be_include("/two") + end + describe "and the FACTERLIB environment variable is set" do it "should include all paths in FACTERLIB" do with_env "FACTERLIB" => "/one/path:/two/path" do |