Class: Puppet::Functions::LocalTypeAliasesBuilder
- Defined in:
- lib/puppet/functions.rb
Overview
The LocalTypeAliasBuilder is used by the ‘local_types’ method to collect the individual type aliases given by the function’s author.
Instance Attribute Summary collapse
- #loader ⇒ Object readonly
- #local_types ⇒ Object readonly
- #parser ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(loader, name) ⇒ LocalTypeAliasesBuilder
constructor
A new instance of LocalTypeAliasesBuilder.
-
#type(assignment_string) ⇒ Object
Defines a local type alias, the given string should be a Puppet Language type alias expression in string form without the leading ‘type’ keyword.
Constructor Details
#initialize(loader, name) ⇒ LocalTypeAliasesBuilder
Returns a new instance of LocalTypeAliasesBuilder.
544 545 546 547 548 549 |
# File 'lib/puppet/functions.rb', line 544 def initialize(loader, name) @loader = Puppet::Pops::Loader::PredefinedLoader.new(loader, :"local_function_#{name}") @local_types = [] # get the shared parser used by puppet's compiler @parser = Puppet::Pops::Parser::EvaluatingParser.singleton() end |
Instance Attribute Details
#loader ⇒ Object (readonly)
542 543 544 |
# File 'lib/puppet/functions.rb', line 542 def loader @loader end |
#local_types ⇒ Object (readonly)
542 543 544 |
# File 'lib/puppet/functions.rb', line 542 def local_types @local_types end |
#parser ⇒ Object (readonly)
542 543 544 |
# File 'lib/puppet/functions.rb', line 542 def parser @parser end |
Instance Method Details
#type(assignment_string) ⇒ Object
Defines a local type alias, the given string should be a Puppet Language type alias expression in string form without the leading ‘type’ keyword. Calls to local_type must be made before the first parameter definition or an error will be raised.
559 560 561 562 563 564 565 |
# File 'lib/puppet/functions.rb', line 559 def type(assignment_string) result = parser.parse_string("type #{assignment_string}", nil) # no file source :-( unless result.body.kind_of?(Puppet::Pops::Model::TypeAlias) raise ArgumentError, "Expected a type alias assignment on the form 'AliasType = T', got '#{assignment_string}'" end @local_types << result.body end |