summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/resource.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/ast/resource.rb')
-rw-r--r--lib/puppet/parser/ast/resource.rb93
1 files changed, 41 insertions, 52 deletions
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 0c58538d5..23207149f 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -3,26 +3,15 @@ require 'puppet/parser/ast/resource_reference'
# Any normal puppet resource declaration. Can point to a definition or a
# builtin type.
class Puppet::Parser::AST
-class Resource < AST::ResourceReference
+class Resource < AST::Branch
associates_doc
- attr_accessor :title, :type, :exported, :virtual
- attr_reader :parameters
+ attr_accessor :type, :instances, :exported, :virtual
# Does not actually return an object; instead sets an object
# in the current scope.
def evaluate(scope)
- # Evaluate all of the specified params.
- paramobjects = parameters.collect { |param|
- param.safeevaluate(scope)
- }
-
- resource_titles = @title.safeevaluate(scope)
-
- # it's easier to always use an array, even for only one name
- resource_titles = [resource_titles] unless resource_titles.is_a?(Array)
-
# We want virtual to be true if exported is true. We can't
# just set :virtual => self.virtual in the initialization,
# because sometimes the :virtual attribute is set *after*
@@ -30,49 +19,49 @@ class Resource < AST::ResourceReference
# is true. Argh, this was a very tough one to track down.
virt = self.virtual || self.exported
- # This is where our implicit iteration takes place; if someone
- # passed an array as the name, then we act just like the called us
- # many times.
- fully_qualified_type, resource_titles = scope.resolve_type_and_titles(type, resource_titles)
+ # First level of implicit iteration: build a resource for each
+ # instance. This handles things like:
+ # file { '/foo': owner => blah; '/bar': owner => blah }
+ @instances.collect { |instance|
- resource_titles.flatten.collect { |resource_title|
- exceptwrap :type => Puppet::ParseError do
- resource = Puppet::Parser::Resource.new(
- fully_qualified_type, resource_title,
- :parameters => paramobjects,
- :file => self.file,
- :line => self.line,
- :exported => self.exported,
- :virtual => virt,
- :source => scope.source,
- :scope => scope,
-
- :strict => true
- )
+ # Evaluate all of the specified params.
+ paramobjects = instance.parameters.collect { |param|
+ param.safeevaluate(scope)
+ }
- # And then store the resource in the compiler.
- # At some point, we need to switch all of this to return
- # resources instead of storing them like this.
- scope.compiler.add_resource(scope, resource)
- resource
- end
- }.reject { |resource| resource.nil? }
- end
+ resource_titles = instance.title.safeevaluate(scope)
+
+ # it's easier to always use an array, even for only one name
+ resource_titles = [resource_titles] unless resource_titles.is_a?(Array)
+
+ fully_qualified_type, resource_titles = scope.resolve_type_and_titles(type, resource_titles)
+
+ # Second level of implicit iteration; build a resource for each
+ # title. This handles things like:
+ # file { ['/foo', '/bar']: owner => blah }
+ resource_titles.flatten.collect { |resource_title|
+ exceptwrap :type => Puppet::ParseError do
+ resource = Puppet::Parser::Resource.new(
+ fully_qualified_type, resource_title,
+ :parameters => paramobjects,
+ :file => self.file,
+ :line => self.line,
+ :exported => self.exported,
+ :virtual => virt,
+ :source => scope.source,
+ :scope => scope,
- # Set the parameters for our object.
- def parameters=(params)
- if params.is_a?(AST::ASTArray)
- @parameters = params
- else
+ :strict => true
+ )
- @parameters = AST::ASTArray.new(
-
- :line => params.line,
- :file => params.file,
-
- :children => [params]
- )
- end
+ # And then store the resource in the compiler.
+ # At some point, we need to switch all of this to return
+ # resources instead of storing them like this.
+ scope.compiler.add_resource(scope, resource)
+ resource
+ end
+ }
+ }.flatten.reject { |resource| resource.nil? }
end
end
end