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.



588
589
590
591
592
593
# File 'lib/puppet/functions.rb', line 588

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)



586
587
588
# File 'lib/puppet/functions.rb', line 586

def loader
  @loader
end

#local_typesObject (readonly)



586
587
588
# File 'lib/puppet/functions.rb', line 586

def local_types
  @local_types
end

#parserObject (readonly)



586
587
588
# File 'lib/puppet/functions.rb', line 586

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’



603
604
605
606
607
608
609
# File 'lib/puppet/functions.rb', line 603

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}'") % { assignment_string: assignment_string }
  end
  @local_types << result.body
end