We previously only supported a single namespace when searching for
resource types et al, but the whole system actually relies on
an array of namespaces and search paths, so this adds
that functionality all the way down, as it were.

Signed-off-by: Luke Kanies <[email protected]>
---
 lib/puppet/parser/scope.rb             |   15 +++------------
 lib/puppet/resource/type_collection.rb |   27 +++++++++++++++++----------
 spec/unit/resource/type_collection.rb  |   11 +++++++++--
 3 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 2d99524..3e3e901 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -22,6 +22,7 @@ class Puppet::Parser::Scope
     attr_accessor :base, :keyword, :nodescope
     attr_accessor :top, :translated, :compiler
     attr_writer :parent
+    attr_reader :namespaces
 
     # A demeterific shortcut to the catalog.
     def catalog
@@ -86,21 +87,11 @@ class Puppet::Parser::Scope
     end
 
     def find_hostclass(name)
-        @namespaces.each do |namespace|
-            if r = known_resource_types.find_hostclass(namespace, name)
-                return r
-            end
-        end
-        return nil
+        known_resource_types.find_hostclass(namespaces, name)
     end
 
     def find_definition(name)
-        @namespaces.each do |namespace|
-            if r = known_resource_types.find_definition(namespace, name)
-                return r
-            end
-        end
-        return nil
+        known_resource_types.find_definition(namespaces, name)
     end
 
     def findresource(string, name = nil)
diff --git a/lib/puppet/resource/type_collection.rb 
b/lib/puppet/resource/type_collection.rb
index 7ca95b1..a0bd2dd 100644
--- a/lib/puppet/resource/type_collection.rb
+++ b/lib/puppet/resource/type_collection.rb
@@ -75,24 +75,31 @@ class Puppet::Resource::TypeCollection
         @definitions[munge_name(name)]
     end
 
-    def find(namespace, name, type)
+    def find(namespaces, name, type)
         if r = find_fully_qualified(name, type)
             return r
         end
 
-        ary = namespace.split("::")
+        namespaces = Array(namespaces)
 
-        while ary.length > 0
-            tmp_namespace = ary.join("::")
-            if r = find_partially_qualified(tmp_namespace, name, type)
-                return r
+        namespaces.each do |namespace|
+            ary = namespace.split("::")
+
+            while ary.length > 0
+                tmp_namespace = ary.join("::")
+                if r = find_partially_qualified(tmp_namespace, name, type)
+                    return r
+                end
+
+                # Delete the second to last object, which reduces our 
namespace by one.
+                ary.pop
             end
 
-            # Delete the second to last object, which reduces our namespace by 
one.
-            ary.pop
+            if result = send(type, name)
+                return result
+            end
         end
-
-        send(type, name)
+        nil
     end
 
     def find_node(name)
diff --git a/spec/unit/resource/type_collection.rb 
b/spec/unit/resource/type_collection.rb
index 2fc364d..3de5e50 100644
--- a/spec/unit/resource/type_collection.rb
+++ b/spec/unit/resource/type_collection.rb
@@ -127,14 +127,21 @@ describe Puppet::Resource::TypeCollection do
             loader.find("namespace", "::foo::bar", :hostclass).should be_nil
         end
 
-        it "should return the partially qualified object if it exists in the 
provided namespace" do
+        it "should return the partially qualified object if it exists in a 
provided namespace" do
             loader = Puppet::Resource::TypeCollection.new("env")
             instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
             loader.add instance
             loader.find("foo", "bar::baz", :hostclass).should equal(instance)
         end
 
-        it "should return the unqualified object if it exists in the provided 
namespace" do
+        it "should be able to find partially qualified objects in any of the 
provided namespaces" do
+            loader = Puppet::Resource::TypeCollection.new("env")
+            instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
+            loader.add instance
+            loader.find(["nons", "foo", "otherns"], "bar::baz", 
:hostclass).should equal(instance)
+        end
+
+        it "should return the unqualified object if it exists in a provided 
namespace" do
             loader = Puppet::Resource::TypeCollection.new("env")
             instance = Puppet::Resource::Type.new(:hostclass, "foo::bar")
             loader.add instance
-- 
1.6.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to