class Puppet::Parser::AST::Resource

Instruction for Resource instantiation. Instantiates resources of both native and user defined types.

Attributes

exported[RW]
instances[RW]
type[RW]
virtual[RW]

Public Class Methods

new(argshash) click to toggle source
Calls superclass method Puppet::Parser::AST::Branch::new
   # File lib/puppet/parser/ast/resource.rb
 9 def initialize(argshash)
10   Puppet.warn_once('deprecations', 'AST::Resource', _('Use of Puppet::Parser::AST::Resource is deprecated and not fully functional'))
11   super(argshash)
12 end

Public Instance Methods

evaluate(scope) click to toggle source

Evaluates resources by adding them to the compiler for lazy evaluation and returning the produced resource references.

   # File lib/puppet/parser/ast/resource.rb
17 def evaluate(scope)
18   # We want virtual to be true if exported is true.  We can't
19   # just set :virtual => self.virtual in the initialization,
20   # because sometimes the :virtual attribute is set *after*
21   # :exported, in which case it clobbers :exported if :exported
22   # is true.  Argh, this was a very tough one to track down.
23   virt = self.virtual || self.exported
24 
25   # First level of implicit iteration: build a resource for each
26   # instance.  This handles things like:
27   # file { '/foo': owner => blah; '/bar': owner => blah }
28   @instances.map do |instance|
29 
30     # Evaluate all of the specified params.
31     paramobjects = instance.parameters.map { |param| param.safeevaluate(scope) }
32 
33     resource_titles = instance.title.safeevaluate(scope)
34 
35     # it's easier to always use an array, even for only one name
36     resource_titles = [resource_titles] unless resource_titles.is_a?(Array)
37 
38     fully_qualified_type, resource_titles = scope.resolve_type_and_titles(type, resource_titles)
39 
40     # Second level of implicit iteration; build a resource for each
41     # title.  This handles things like:
42     # file { ['/foo', '/bar']: owner => blah }
43     resource_titles.flatten.map do |resource_title|
44       exceptwrap :type => Puppet::ParseError do
45         resource = Puppet::Parser::Resource.new(
46         fully_qualified_type, resource_title,
47           :parameters => paramobjects,
48           :file => self.file,
49           :line => self.line,
50           :exported => self.exported,
51           :virtual => virt,
52           :source => scope.source,
53           :scope => scope,
54           :strict => true
55         )
56 
57         if resource.resource_type.is_a? Puppet::Resource::Type
58           resource.resource_type.instantiate_resource(scope, resource)
59         end
60         scope.compiler.add_resource(scope, resource)
61         scope.compiler.evaluate_classes([resource_title], scope, false) if fully_qualified_type == 'class'
62         resource
63       end
64     end
65   end.flatten.reject { |resource| resource.nil? }
66 end