diff options
-rw-r--r-- | lib/puppet/type.rb | 20 | ||||
-rw-r--r-- | test/types/type.rb | 18 |
2 files changed, 29 insertions, 9 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index c061380bd..135b3b427 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -201,7 +201,7 @@ class Type < Puppet::Element if @objects.has_key?(name) and self.isomorphic? raise Puppet::Error.new( "Object '%s' of type '%s' already exists with id '%s' vs. '%s'" % - [name,newobj.class.name, + [name, newobj.class.name, @objects[name].object_id,newobj.object_id] ) else @@ -353,6 +353,10 @@ class Type < Puppet::Element @@metaparams.each { |p| @@metaparamhash[name] = p } end + def self.eachmetaparam + @@metaparams.each { |p| yield p.name } + end + # Create a new parameter. Requires a block and a name, stores it in the # @parameters array, and does some basic checking on it. def self.newparam(name, &block) @@ -1480,10 +1484,10 @@ class Type < Puppet::Element # Documentation methods def self.paramdoc(param) - @paramdoc[param] + @paramhash[param].doc end def self.metaparamdoc(metaparam) - @@metaparamdoc[metaparam] + @@metaparamhash[metaparam].doc end # Add all of the meta parameters. @@ -1592,12 +1596,20 @@ class Type < Puppet::Element you are creating long commands using exec or when many different systems call a given package different names." - munge do |*aliases| + munge do |aliases| unless aliases.is_a?(Array) aliases = [aliases] end @parent.info "Adding aliases %s" % aliases.join(", ") aliases.each do |other| + if obj = @parent.class[other] + unless obj == @parent + raise Puppet::Error, + "%s an not create alias %s: object already exists" % + [@parent.name, other] + end + next + end @parent.class[other] = @parent end end diff --git a/test/types/type.rb b/test/types/type.rb index 6271fa43c..7a95e2574 100644 --- a/test/types/type.rb +++ b/test/types/type.rb @@ -135,11 +135,19 @@ class TestType < Test::Unit::TestCase def test_aliasing file = tempfile() - baseobj = Puppet.type(:file).create( - :name => file, - :create => true, - :alias => "funtest" - ) + baseobj = nil + assert_nothing_raised { + baseobj = Puppet.type(:file).create( + :name => file, + :create => true, + :alias => ["funtest"] + ) + } + + # Verify we adding ourselves as an alias isn't an error. + assert_nothing_raised { + baseobj[:alias] = file + } assert_instance_of(Puppet.type(:file), Puppet.type(:file)["funtest"], "Could not retrieve alias") |