[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

James Turnbull james at lovedthanlost.net
Fri Jan 23 14:21:26 UTC 2009


The following commit has been merged in the master branch:
commit 00d5fe403d754e61ae32f01f6879dfc93bfa6111
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Sun Oct 5 18:52:20 2008 +0200

    Fix #1115 - Allow checking tags/classes from ERb templates
    
    Add to predefined variables to the ERB template space. "classes"
    and "tags" which provide arrays of all the defined classes and tags
    for a node.
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb
index 3b74e62..fc716b0 100644
--- a/lib/puppet/parser/templatewrapper.rb
+++ b/lib/puppet/parser/templatewrapper.rb
@@ -37,6 +37,16 @@ class Puppet::Parser::TemplateWrapper
         end
     end
 
+    # Allow templates to access the defined classes
+    def classes
+        return scope.catalog.classes
+    end
+
+    # Allow templates to access the defined tags
+    def tags
+        return scope.catalog.tags
+    end
+
     # Ruby treats variables like methods, so we used to expose variables
     # within scope to the ERB code via method_missing.  As per RedMine #1427,
     # though, this means that conflicts between methods in our inheritance
diff --git a/spec/unit/parser/templatewrapper.rb b/spec/unit/parser/templatewrapper.rb
index 2d4bd14..20ea769 100755
--- a/spec/unit/parser/templatewrapper.rb
+++ b/spec/unit/parser/templatewrapper.rb
@@ -55,6 +55,20 @@ describe Puppet::Parser::TemplateWrapper do
         tw.has_variable?("chicken").should eql(false)
     end
 
+    it "should allow you to retrieve the defined classes with classes" do
+        catalog = mock 'catalog', :classes => ["class1", "class2"]
+        @scope.expects(:catalog).returns( catalog )
+        tw = Puppet::Parser::TemplateWrapper.new(@scope, @file)
+        tw.classes().should == ["class1", "class2"]
+    end
+
+    it "should allow you to retrieve the defined tags with tags" do
+        catalog = mock 'catalog', :tags => ["tag1", "tag2"]
+        @scope.expects(:catalog).returns( catalog )
+        tw = Puppet::Parser::TemplateWrapper.new(@scope, @file)
+        tw.tags().should == ["tag1","tag2"]
+    end
+
     it "should set all of the scope's variables as instance variables" do
         template_mock = mock("template", :result => "woot!")
         File.expects(:read).with("/tmp/fake_template").returns("template contents")

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list