Class: Puppet::Parser::AST::ResourceOverride
- Inherits:
-
Resource
- Object
- Puppet::Parser::AST
- Branch
- ResourceReference
- Resource
- Puppet::Parser::AST::ResourceOverride
- Defined in:
- lib/puppet/parser/ast/resource_override.rb
Overview
Set a parameter on a resource specification created somewhere else in the configuration. The object is responsible for verifying that this is allowed.
Constant Summary
Constants inherited from Puppet::Parser::AST
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Attributes inherited from Resource
#exported, #title, #type, #virtual
Attributes inherited from ResourceReference
Attributes inherited from Branch
Attributes inherited from Puppet::Parser::AST
Attributes included from Util::Docs
Attributes included from FileCollection::Lookup
Instance Method Summary collapse
-
#each ⇒ Object
Iterate across all of our children.
-
#evaluate(scope) ⇒ Object
Does not actually return an object; instead sets an object in the current scope.
-
#initialize(hash) ⇒ ResourceOverride
constructor
Create our ResourceDef.
Methods inherited from ResourceReference
Methods inherited from Puppet::Parser::AST
associates_doc, #evaluate_match, #inspect, #parsefail, #parsewrap, #safeevaluate, settor?, #use_docs
Methods included from Util::Docs
#desc, #dochook, #doctable, #nodoc?, #pad, scrub
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Methods included from FileCollection::Lookup
#file, #file=, #file_collection
Constructor Details
#initialize(hash) ⇒ ResourceOverride
Create our ResourceDef. Handles type checking for us.
61 62 63 64 65 66 |
# File 'lib/puppet/parser/ast/resource_override.rb', line 61 def initialize(hash) @checked = false super #self.typecheck(@type.value) end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
10 11 12 |
# File 'lib/puppet/parser/ast/resource_override.rb', line 10 def object @object end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
11 12 13 |
# File 'lib/puppet/parser/ast/resource_override.rb', line 11 def parameters @parameters end |
Instance Method Details
#each ⇒ Object
Iterate across all of our children.
14 15 16 17 18 19 |
# File 'lib/puppet/parser/ast/resource_override.rb', line 14 def each [@object,@parameters].flatten.each { |param| #Puppet.debug("yielding param #{param}") yield param } end |
#evaluate(scope) ⇒ Object
Does not actually return an object; instead sets an object in the current scope.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/parser/ast/resource_override.rb', line 23 def evaluate(scope) # Get our object reference. resource = @object.safeevaluate(scope) hash = {} # Evaluate all of the specified params. params = @parameters.collect { |param| param.safeevaluate(scope) } # Now we just create a normal resource, but we call a very different # method on the scope. resource = [resource] unless resource.is_a?(Array) resource = resource.collect do |r| res = Puppet::Parser::Resource.new( r.type, r.title, :parameters => 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.length == 1 ? resource.pop : resource) end |