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