+1
(Comments below.)
On Oct 4, 2008, at 7:23 AM, Brice Figureau wrote:
>
> 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"] ]
> }
>
> Obey to original API, that is return sole object when
> called in sole object context.
>
> Signed-off-by: Brice Figureau <[EMAIL PROTECTED]>
> ---
> lib/puppet/parser/ast/resource_override.rb | 37 +-
> lib/puppet/parser/ast/resource_reference.rb | 12 +-
> lib/puppet/parser/grammar.ra | 4 +-
> lib/puppet/parser/parser.rb | 714 ++++++++++++
> +--------------
> 4 files changed, 380 insertions(+), 387 deletions(-)
>
> diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/
> parser/ast/resource_override.rb
> index f9464ac..5a247f9 100644
> --- a/lib/puppet/parser/ast/resource_override.rb
> +++ b/lib/puppet/parser/ast/resource_override.rb
> @@ -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
> + object = [object] unless object.is_a?(Array)
> +
> + object = object.collect do |o|
> + obj = Puppet::Parser::Resource.new(
> + :type => o.type,
> + :title => o.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
> + end
> + # decapsulate array in case of only one item
> + return object.pop if object.length == 1
> + return object
> end
The use of 'object' here is from before we'd chosen the word
'resource' -- it'd be great if you renamed that attribute to 'resource'.
>
> # 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 4bb4116..6050522 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)
> + title = title.collect { |t| qualified_class(scope,
> t) }
> else
> objtype = qualified_type(scope)
> end
>
> - return Puppet::Parser::Resource::Reference.new(
> - :type => objtype, :title => title
> - )
> + title = title.collect { |t|
> Puppet::Parser::Resource::Reference.new(
> + :type => objtype, :title => t
> + ) }
> + return title.pop if title.length == 1
> + return title
> end
Same here on 'objtype' -- that should be 'resource_type' or something
similar.
Note that there are also some tests for resource_reference in test/
language/ast/resource_reference.rb.
--
Always behave like a duck - keep calm and unruffled on the surface but
paddle like the devil underneath. -- Jacob Braude
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---