Class: Puppet::Parser::AST::PopsBridge::Program
- Inherits:
-
TopLevelConstruct
- Object
- Puppet::Parser::AST
- TopLevelConstruct
- Puppet::Parser::AST::PopsBridge::Program
- Defined in:
- lib/puppet/parser/ast/pops_bridge.rb
Overview
Bridges the top level “Program” produced by the pops parser. Its main purpose is to give one point where all definitions are instantiated (actually defined since the Puppet 3x terminology is somewhat misleading - the definitions are instantiated, but instances of the created types are not created, that happens when classes are included / required, nodes are matched and when resources are instantiated by a resource expression (which is also used to instantiate a host class).
Constant Summary
Constants inherited from Puppet::Parser::AST
Constants included from Util::Docs
Instance Attribute Summary collapse
- #context ⇒ Object readonly
- #program_model ⇒ Object readonly
Attributes inherited from Puppet::Parser::AST
#file, #line, #parent, #pos, #scope
Attributes included from Util::Docs
Instance Method Summary collapse
-
#each {|_self| ... } ⇒ Object
Adapts to 3x where top level constructs needs to have each to iterate over children.
- #evaluate(scope) ⇒ Object
-
#initialize(program_model, context = {}) ⇒ Program
constructor
A new instance of Program.
-
#instantiate(modname) ⇒ Object
This is the 3x API, the 3x AST searches through all code to find the instructions that can be instantiated.
Methods inherited from Puppet::Parser::AST
associates_doc, #evaluate_match, #inspect, #parsefail, #parsewrap, #safeevaluate, #use_docs
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Constructor Details
#initialize(program_model, context = {}) ⇒ Program
Returns a new instance of Program.
68 69 70 71 72 73 |
# File 'lib/puppet/parser/ast/pops_bridge.rb', line 68 def initialize(program_model, context = {}) @program_model = program_model @context = context @ast_transformer ||= Puppet::Pops::Model::AstTransformer.new(@context[:file]) @@evaluator ||= Puppet::Pops::Parser::EvaluatingParser.new() end |
Instance Attribute Details
#context ⇒ Object (readonly)
66 67 68 |
# File 'lib/puppet/parser/ast/pops_bridge.rb', line 66 def context @context end |
#program_model ⇒ Object (readonly)
66 67 68 |
# File 'lib/puppet/parser/ast/pops_bridge.rb', line 66 def program_model @program_model end |
Instance Method Details
#each {|_self| ... } ⇒ Object
Adapts to 3x where top level constructs needs to have each to iterate over children. Short circuit this by yielding self. This means that the HostClass container will call this bridge instance with ‘instantiate`.
102 103 104 |
# File 'lib/puppet/parser/ast/pops_bridge.rb', line 102 def each yield self end |
#evaluate(scope) ⇒ Object
95 96 97 |
# File 'lib/puppet/parser/ast/pops_bridge.rb', line 95 def evaluate(scope) @@evaluator.evaluate(scope, program_model) end |
#instantiate(modname) ⇒ Object
This is the 3x API, the 3x AST searches through all code to find the instructions that can be instantiated. This Pops-model based instantiation relies on the parser to build this list while parsing (which is more efficient as it avoids one full scan of all logic via recursive enumeration/yield)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/puppet/parser/ast/pops_bridge.rb', line 79 def instantiate(modname) @program_model.definitions.collect do |d| case d when Puppet::Pops::Model::HostClassDefinition instantiate_HostClassDefinition(d, modname) when Puppet::Pops::Model::ResourceTypeDefinition instantiate_ResourceTypeDefinition(d, modname) when Puppet::Pops::Model::NodeDefinition instantiate_NodeDefinition(d, modname) else raise Puppet::ParseError, "Internal Error: Unknown type of definition - got '#{d.class}'" end end.flatten().compact() # flatten since node definition may have returned an array # Compact since functions are not understood by compiler end |