summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-01 00:30:07 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-01 00:30:07 +0000
commit76ff83d86ce2bfaea69bb57af766833ea21095a5 (patch)
tree42084c63e524c378dee4390dfd742704cba69418
parentb08816b000242def032f7099cad2d27310ed389c (diff)
downloadpuppet-76ff83d86ce2bfaea69bb57af766833ea21095a5.tar.gz
puppet-76ff83d86ce2bfaea69bb57af766833ea21095a5.tar.xz
puppet-76ff83d86ce2bfaea69bb57af766833ea21095a5.zip
Fixing #161. Basically, AST::ObjectDef now catches when users specify a name as a parameter instead of the name before the colon and modify the results accordingly. This catches this kind of problem, and the normal name handling picks up everything else.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1229 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/parser/ast/objectdef.rb33
-rwxr-xr-xtest/language/ast.rb24
2 files changed, 49 insertions, 8 deletions
diff --git a/lib/puppet/parser/ast/objectdef.rb b/lib/puppet/parser/ast/objectdef.rb
index 7ccc9851a..7ed64388e 100644
--- a/lib/puppet/parser/ast/objectdef.rb
+++ b/lib/puppet/parser/ast/objectdef.rb
@@ -55,23 +55,40 @@ class Puppet::Parser::AST
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
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 7dc8d80d3..8860f4ad3 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -753,6 +753,30 @@ class TestAST < Test::Unit::TestCase
end
end
+ # Make sure we catch names that are specified like parameters.
+ def test_name_or_param
+ obj = nil
+ assert_nothing_raised {
+ obj = AST::ObjectDef.new(
+ :type => nameobj("file"),
+ :params => astarray(AST::ObjectParam.new(
+ :param => stringobj("name"),
+ :value => stringobj("yayness")
+ ))
+ )
+ }
+
+ scope = Puppet::Parser::Scope.new
+
+ trans = nil
+ assert_nothing_raised {
+ trans = scope.evaluate(:ast => obj, :facts => {})
+ }
+
+ transobj = trans.shift
+ assert(transobj.name, "Name did not convert from param to name")
+ end
+
if defined? ActiveRecord
# Verify that our collection stuff works.
def test_collection