diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2008-10-04 16:27:51 +0200 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2008-10-05 14:35:44 +1100 |
| commit | 750e9abc64af58e547e7b1ad5698c71feb071bf6 (patch) | |
| tree | bf5c7649dcccf29903e320d4d2d10713c9ccc03d /lib/puppet/parser/ast | |
| parent | 782181e0da1bb6f5a091046ad68989300c508176 (diff) | |
| download | puppet-750e9abc64af58e547e7b1ad5698c71feb071bf6.tar.gz puppet-750e9abc64af58e547e7b1ad5698c71feb071bf6.tar.xz puppet-750e9abc64af58e547e7b1ad5698c71feb071bf6.zip | |
Fix #381 - Allow multiple resource overrides or references
Allow this syntax:
Resource[title1,title2] { param => value }
as a compact form of
Resource[title1] { param => value }
Resource[title2] { param => value }
This patch also introduces for free the possibility to group
class references by type:
exec {
test:
require => File["file1","file2","File3"]
}
which is completely equivalent to:
exec {
test:
require => [ File["file1"],File["file2"],File["File3"] ]
}
Diffstat (limited to 'lib/puppet/parser/ast')
| -rw-r--r-- | lib/puppet/parser/ast/resource_override.rb | 39 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/resource_reference.rb | 16 |
2 files changed, 33 insertions, 22 deletions
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb index f9464acda..8380dcd00 100644 --- a/lib/puppet/parser/ast/resource_override.rb +++ b/lib/puppet/parser/ast/resource_override.rb @@ -19,7 +19,7 @@ class Puppet::Parser::AST # in the current scope. def evaluate(scope) # Get our object reference. - object = @object.safeevaluate(scope) + resource = @object.safeevaluate(scope) hash = {} @@ -30,21 +30,28 @@ class Puppet::Parser::AST # Now we just create a normal resource, but we call a very different # method on the scope. - obj = Puppet::Parser::Resource.new( - :type => object.type, - :title => object.title, - :params => params, - :file => @file, - :line => @line, - :source => scope.source, - :scope => scope - ) - - # Now we tell the scope that it's an override, and it behaves as - # necessary. - scope.compiler.add_override(obj) - - obj + resource = [resource] unless resource.is_a?(Array) + + resource = resource.collect do |r| + res = Puppet::Parser::Resource.new( + :type => r.type, + :title => r.title, + :params => params, + :file => @file, + :line => @line, + :source => scope.source, + :scope => scope + ) + + # Now we tell the scope that it's an override, and it behaves as + # necessary. + scope.compiler.add_override(res) + + res + end + # decapsulate array in case of only one item + return resource.pop if resource.length == 1 + return resource end # Create our ResourceDef. Handles type checking for us. diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb index 4bb41165a..e5e2dce99 100644 --- a/lib/puppet/parser/ast/resource_reference.rb +++ b/lib/puppet/parser/ast/resource_reference.rb @@ -24,16 +24,20 @@ class Puppet::Parser::AST # and name. def evaluate(scope) title = @title.safeevaluate(scope) + title = [title] unless title.is_a?(Array) + if @type.to_s.downcase == "class" - objtype = "class" - title = qualified_class(scope, title) + resource_type = "class" + title = title.collect { |t| qualified_class(scope, t) } else - objtype = qualified_type(scope) + resource_type = qualified_type(scope) end - return Puppet::Parser::Resource::Reference.new( - :type => objtype, :title => title - ) + title = title.collect { |t| Puppet::Parser::Resource::Reference.new( + :type => resource_type, :title => t + ) } + return title.pop if title.length == 1 + return title end # Look up a fully qualified class name. |
