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/resource_override.rb | |
| 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/resource_override.rb')
| -rw-r--r-- | lib/puppet/parser/ast/resource_override.rb | 39 |
1 files changed, 23 insertions, 16 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. |
