Method: Puppet::Pal::Compiler#type

Defined in:
lib/puppet/pal/compiler.rb

#type(type_string) ⇒ Puppet::Pops::Types::PAnyType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a puppet data type given in String format and returns that type, or raises an error. A type is needed in calls to ‘new` to create an instance of the data type, or to perform type checking of values - typically using `type.instance?(obj)` to check if `obj` is an instance of the type.

Examples:

Verify if obj is an instance of a data type

# evaluates to true
pal.type('Enum[red, blue]').instance?("blue")

Create an instance of a data type

# using an already create type
t = pal.type('Car')
pal.create(t, 'color' => 'black', 'make' => 't-ford')

# letting 'new_object' parse the type from a string
pal.create('Car', 'color' => 'black', 'make' => 't-ford')

Parameters:

  • type_string (String)

    a puppet language data type

Returns:



178
179
180
# File 'lib/puppet/pal/compiler.rb', line 178

def type(type_string)
  Puppet::Pops::Types::TypeParser.singleton.parse(type_string)
end