Class: Puppet::Pal::CatalogCompiler
- Defined in:
- lib/puppet/pal/catalog_compiler.rb
Overview
A CatalogCompiler is a compiler that builds a catalog of resources and dependencies as a side effect of evaluating puppet language code. When the compilation of the given input manifest(s)/code string/file is finished the catalog is complete for encoding and use. It is also possible to evaluate more strings within the same compilation context to add or remove things from the catalog.
Instance Method Summary collapse
-
#catalog_data_hash ⇒ Object
Returns a hash representation of the compiled catalog.
-
#compile_additions ⇒ Void
Compiles the result of additional evaluation taking place in a PAL catalog compilation.
-
#evaluate(ast) ⇒ Object
Evaluates an AST obtained from ‘parse_string` or `parse_file` in topscope.
-
#evaluate_additions ⇒ Object
Evaluates all lazy constructs that were produced as a side effect of evaluating puppet logic.
-
#evaluate_ast_node ⇒ Object
Attempts to evaluate AST for node defnintions puppet.com/docs/puppet/latest/lang_node_definitions.html if there are any.
-
#has_catalog? ⇒ Boolean
Returns true if this is a compiler that compiles a catalog.
-
#validate ⇒ Object
Validates the state of the catalog (without performing evaluation of any elements requiring lazy evaluation. Can be called multiple times..
-
#with_json_encoding(pretty: true, exclude_virtual: true) {|JsonCatalogEncoder.new(catalog, pretty: pretty, exclude_virtual: exclude_virtual)| ... } ⇒ Object
Calls a block of code and yields a configured ‘JsonCatalogEncoder` to the block.
Methods inherited from Compiler
#call_function, #create, #evaluate_file, #evaluate_literal, #evaluate_string, #function_signature, #initialize, #list_functions, #parse_file, #parse_string, #type
Constructor Details
This class inherits a constructor from Puppet::Pal::Compiler
Instance Method Details
#catalog_data_hash ⇒ Object
Returns a hash representation of the compiled catalog.
44 45 46 |
# File 'lib/puppet/pal/catalog_compiler.rb', line 44 def catalog_data_hash catalog.to_data_hash end |
#compile_additions ⇒ Void
Compiles the result of additional evaluation taking place in a PAL catalog compilation. This will evaluate all lazy constructs until all have been evaluated, and will the validate the result.
This should be called if evaluating string or files of puppet logic after the initial compilation taking place by giving PAL a manifest or code-string. This method should be called when a series of evaluation should have reached a valid state (there should be no dangling relationships (to resources that does not exist).
As an alternative the methods ‘evaluate_additions` can be called without any requirements on consistency and then calling `validate` at the end.
Can be called multiple times.
82 83 84 |
# File 'lib/puppet/pal/catalog_compiler.rb', line 82 def compile_additions internal_compiler.compile_additions end |
#evaluate(ast) ⇒ Object
Evaluates an AST obtained from ‘parse_string` or `parse_file` in topscope. If the ast is a `Puppet::Pops::Model::Program` (what is returned from the `parse` methods, any definitions in the program (that is, any function, plan, etc. that is defined will be made available for use).
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/puppet/pal/catalog_compiler.rb', line 55 def evaluate(ast) if ast.is_a?(Puppet::Pops::Model::Program) bridged = Puppet::Parser::AST::PopsBridge::Program.new(ast) # define all catalog types internal_compiler.environment.known_resource_types.import_ast(bridged, "") bridged.evaluate(internal_compiler.topscope) else internal_evaluator.evaluate(topscope, ast) end end |
#evaluate_additions ⇒ Object
Evaluates all lazy constructs that were produced as a side effect of evaluating puppet logic. Can be called multiple times.
96 97 98 |
# File 'lib/puppet/pal/catalog_compiler.rb', line 96 def evaluate_additions internal_compiler.evaluate_additions end |
#evaluate_ast_node ⇒ Object
Attempts to evaluate AST for node defnintions puppet.com/docs/puppet/latest/lang_node_definitions.html if there are any.
102 103 104 |
# File 'lib/puppet/pal/catalog_compiler.rb', line 102 def evaluate_ast_node internal_compiler.evaluate_ast_node end |
#has_catalog? ⇒ Boolean
Returns true if this is a compiler that compiles a catalog. This implementation returns ‘true`
23 24 25 |
# File 'lib/puppet/pal/catalog_compiler.rb', line 23 def has_catalog? true end |
#validate ⇒ Object
Validates the state of the catalog (without performing evaluation of any elements requiring lazy evaluation. Can be called multiple times.
89 90 91 |
# File 'lib/puppet/pal/catalog_compiler.rb', line 89 def validate internal_compiler.validate end |
#with_json_encoding(pretty: true, exclude_virtual: true) {|JsonCatalogEncoder.new(catalog, pretty: pretty, exclude_virtual: exclude_virtual)| ... } ⇒ Object
Calls a block of code and yields a configured ‘JsonCatalogEncoder` to the block.
37 38 39 |
# File 'lib/puppet/pal/catalog_compiler.rb', line 37 def with_json_encoding(pretty: true, exclude_virtual: true) yield JsonCatalogEncoder.new(catalog, pretty: pretty, exclude_virtual: exclude_virtual) end |