lib/puppet/parser/ast/objectdef.rb in puppet-0.16.0 vs lib/puppet/parser/ast/objectdef.rb in puppet-0.18.4

- old
+ new

@@ -1,10 +1,10 @@ class Puppet::Parser::AST # Any normal puppet object declaration. Can result in a class or a # component, in addition to builtin types. class ObjectDef < AST::Branch - attr_accessor :name, :type + attr_accessor :name, :type, :collectable attr_reader :params # probably not used at all def []=(index,obj) @params[index] = obj @@ -53,27 +53,44 @@ error.file = self.file error.backtrace = detail.backtrace raise error end + hash = {} + # Evaluate all of the specified params. + @params.each { |param| + ary = param.safeevaluate(:scope => scope) + hash[ary[0]] = ary[1] + } + objnames = [nil] - # Autogenerate the name if one was not passed. + # Determine our name if we have one. if self.name objnames = @name.safeevaluate(:scope => scope) # it's easier to always use an array, even for only one name unless objnames.is_a?(Array) objnames = [objnames] end - end + else + # See if they specified the name as a parameter instead of as a + # normal name (i.e., before the colon). + unless object # we're a builtin + if objclass = Puppet::Type.type(objtype) + namevar = objclass.namevar - hash = {} + tmp = hash["name"] || hash[namevar.to_s] - # then set all of the specified params - @params.each { |param| - ary = param.safeevaluate(:scope => scope) - hash[ary[0]] = ary[1] - } + if tmp + objnames = [tmp] + end + else + # this should never happen, because we've already + # typechecked, but it's no real problem if it does happen. + # We just end up with an object with no name. + end + end + end # this is where our implicit iteration takes place; # if someone passed an array as the name, then we act # just like the called us many times objnames.collect { |objname| @@ -89,10 +106,11 @@ obj = scope.setobject( :type => objtype, :name => objname, :arguments => hash, :file => @file, - :line => @line + :line => @line, + :collectable => self.collectable ) rescue Puppet::ParseError => except except.line = self.line except.file = self.file raise except