Since there isn't any unit test for puppetdoc rdoc code (my fault),
nobody noticed it was using direct access to the parser AST array.
This changeset fixes the way puppetdoc uses the parser results.

Signed-off-by: Brice Figureau <[email protected]>
---
 lib/puppet/parser/loaded_code.rb |    6 ++++++
 lib/puppet/util/rdoc/parser.rb   |    6 +++---
 spec/unit/parser/loaded_code.rb  |    7 +++++++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/puppet/parser/loaded_code.rb b/lib/puppet/parser/loaded_code.rb
index 7c918d4..6c51961 100644
--- a/lib/puppet/parser/loaded_code.rb
+++ b/lib/puppet/parser/loaded_code.rb
@@ -65,6 +65,12 @@ class Puppet::Parser::LoadedCode
         find(namespace, name, :definition)
     end
 
+    [:hostclasses, :nodes, :definitions].each do |m|
+        define_method(m) do
+            instance_variable_get("@#{m}").dup
+        end
+    end
+
     private
 
     def find_fully_qualified(name, type)
diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
index 1d4fa96..7954865 100644
--- a/lib/puppet/util/rdoc/parser.rb
+++ b/lib/puppet/util/rdoc/parser.rb
@@ -281,7 +281,7 @@ class Parser
     # that contains the documentation
     def parse_elements(container)
         Puppet.debug "rdoc: scanning manifest"
-        @ast[:classes].values.sort { |a,b| a.classname <=> b.classname }.each 
do |klass|
+        @ast.hostclasses.values.sort { |a,b| a.classname <=> b.classname 
}.each do |klass|
             name = klass.classname
             if klass.file == @input_file_name
                 unless name.empty?
@@ -294,13 +294,13 @@ class Parser
             end
         end
 
-        @ast[:definitions].each do |name, define|
+        @ast.definitions.each do |name, define|
             if define.file == @input_file_name
                 document_define(name,define,container)
             end
         end
 
-        @ast[:nodes].each do |name, node|
+        @ast.nodes.each do |name, node|
             if node.file == @input_file_name
                 document_node(name,node,container)
             end
diff --git a/spec/unit/parser/loaded_code.rb b/spec/unit/parser/loaded_code.rb
index 50f6b93..d2986bf 100644
--- a/spec/unit/parser/loaded_code.rb
+++ b/spec/unit/parser/loaded_code.rb
@@ -25,6 +25,13 @@ describe Puppet::Parser::LoadedCode do
         it "should return nil when asked for a #{data} that has not been 
added" do
             Puppet::Parser::LoadedCode.new.send(data, "foo").should be_nil
         end
+
+        it "should be able to retrieve all #{data}s" do
+            plurals = { "hostclass" => "hostclasses", "node" => "nodes", 
"definition" => "definitions" }
+            loader = Puppet::Parser::LoadedCode.new
+            loader.send("add_" + data , "foo", "bar")
+            loader.send(plurals[data]).should == { "foo" => "bar" }
+        end
     end
 
     describe "when finding a qualified instance" do
-- 
1.6.0.2


--~--~---------~--~----~------------~-------~--~----~
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