Class: Puppet::Functions::LocalTypeAliasesBuilder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#loaderObject (readonly)



542
543
544
# File 'lib/puppet/functions.rb', line 542

def loader
  @loader
end

#local_typesObject (readonly)



542
543
544
# File 'lib/puppet/functions.rb', line 542

def local_types
  @local_types
end

#parserObject (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.

Parameters:

  • assignment_string (String)

    a string on the form ‘AliasType = ExistingType’



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