summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-19 00:46:25 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-19 00:46:25 +0000
commita212ea748f13296489ef39a6404b6ff1ff2def78 (patch)
tree256780179e0bf4718a2d90f9256e945a0f1c4db2 /lib/puppet/parser
parent90bdc33e440eba602426f709b31b8fca430e19d6 (diff)
downloadpuppet-a212ea748f13296489ef39a6404b6ff1ff2def78.tar.gz
puppet-a212ea748f13296489ef39a6404b6ff1ff2def78.tar.xz
puppet-a212ea748f13296489ef39a6404b6ff1ff2def78.zip
Adding #539. Definitions can now have titles, and both $title and $name are guaranteed to be set within any definition.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2301 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/ast/component.rb22
-rw-r--r--lib/puppet/parser/resource.rb7
2 files changed, 20 insertions, 9 deletions
diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb
index 8f82d530a..9e3179edb 100644
--- a/lib/puppet/parser/ast/component.rb
+++ b/lib/puppet/parser/ast/component.rb
@@ -28,13 +28,15 @@ class Puppet::Parser::AST
def evaluate(hash)
origscope = hash[:scope]
objtype = hash[:type]
- name = hash[:name]
+ title = hash[:title]
args = symbolize_options(hash[:arguments] || {})
+ name = args[:name] || title
+
exported = hash[:exported]
pscope = origscope
- scope = subscope(pscope, name)
+ scope = subscope(pscope, title)
if exported or origscope.exported?
scope.exported = true
@@ -46,8 +48,10 @@ class Puppet::Parser::AST
scope.tag(@type)
end
- unless name.nil? or name =~ /[^\w]/ or name == ""
- scope.tag(name)
+ [name, title].each do |str|
+ unless str.nil? or str =~ /[^\w]/ or str == ""
+ scope.tag(str)
+ end
end
# define all of the arguments in our local scope
@@ -66,7 +70,7 @@ class Puppet::Parser::AST
# [default.inspect, arg.inspect, @name.inspect]
else
parsefail "Must pass %s to %s of type %s" %
- [arg,name,@type]
+ [arg,title,@type]
end
end
}
@@ -84,7 +88,11 @@ class Puppet::Parser::AST
end
}
- unless args.include? "name"
+ unless args.include? :title
+ scope.setvar("title",title)
+ end
+
+ unless args.include? :name
scope.setvar("name",name)
end
@@ -192,6 +200,8 @@ class Puppet::Parser::AST
if @arguments.include?(param)
# It's a valid arg for us
return true
+ elsif param == "name"
+ return true
# elsif defined? @parentclass and @parentclass
# # Else, check any existing parent
# if parent = @scope.lookuptype(@parentclass) and parent != []
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 31d43bd18..bdace28cd 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -91,7 +91,7 @@ class Puppet::Parser::Resource
scope.deleteresource(self)
return klass.evaluate(:scope => scope,
:type => self.type,
- :name => self.title,
+ :title => self.title,
:arguments => self.to_hash,
:scope => self.scope,
:exported => self.exported
@@ -182,16 +182,17 @@ class Puppet::Parser::Resource
# Verify that all passed parameters are valid. This throws an error if there's
# a problem, so we don't have to worry about the return value.
def paramcheck(param)
+ param = param.to_s
# Now make sure it's a valid argument to our class. These checks
# are organized in order of commonhood -- most types, it's a valid argument
# and paramcheck is enabled.
if @ref.typeclass.validattr?(param)
true
- elsif (param == "name" or param == "title") # always allow these
+ elsif %w{name title}.include?(param) # always allow these
true
elsif paramcheck?
self.fail Puppet::ParseError, "Invalid parameter '%s' for type '%s'" %
- [param, @ref.type]
+ [param.inspect, @ref.type]
end
end