diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-07-23 23:09:34 +0200 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-07-24 09:48:16 +1000 |
commit | d95b687045920c7d7fed5da1fe03b0feac86327a (patch) | |
tree | a470f6ed0f6d16d8f51e50db3b6135650a90fa23 | |
parent | ef5c4aeb1f58bd37e8b4ea0fa17fbdbc2fbf7677 (diff) | |
download | puppet-d95b687045920c7d7fed5da1fe03b0feac86327a.tar.gz puppet-d95b687045920c7d7fed5da1fe03b0feac86327a.tar.xz puppet-d95b687045920c7d7fed5da1fe03b0feac86327a.zip |
Fix #2439 - let puppetdoc use loaded_code
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 <brice-puppet@daysofwonder.com>
-rw-r--r-- | lib/puppet/parser/loaded_code.rb | 6 | ||||
-rw-r--r-- | lib/puppet/util/rdoc/parser.rb | 6 | ||||
-rw-r--r-- | 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 7c918d4c3..6c519613f 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 1d4fa966a..7954865f8 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 50f6b930c..d2986bf2c 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 |