Class: Puppet::Pops::Types::TypedModelObject

Inherits:
Object
  • Object
show all
Includes:
Adaptable, PuppetObject, Visitable
Defined in:
lib/puppet/pops/types/types.rb

Overview

The Types model is a model of Puppet Language types.

The exact relationship between types is not visible in this model wrt. the PDataType which is an abstraction of Scalar, Array, and Hash[Scalar, Data] nested to any depth. This means it is not possible to infer the type by simply looking at the inheritance hierarchy. The TypeCalculator should be used to answer questions about types. The TypeFactory should be used to create an instance of a type whenever one is needed.

The implementation of the Types model contains methods that are required for the type objects to behave as expected when comparing them and using them as keys in hashes. (No other logic is, or should be included directly in the model’s classes).

TODO: See PUP-2978 for possible performance optimization

Direct Known Subclasses

PAnyType, PStructElement

Class Method Summary collapse

Methods included from Visitable

#accept

Methods included from PuppetObject

#_ptype

Class Method Details

._ptypeObject



53
54
55
# File 'lib/puppet/pops/types/types.rb', line 53

def self._ptype
  @type
end

.create_ptype(loader, ir, parent_name, attributes_hash = EMPTY_HASH) ⇒ Object



57
58
59
# File 'lib/puppet/pops/types/types.rb', line 57

def self.create_ptype(loader, ir, parent_name, attributes_hash = EMPTY_HASH)
  @type = Pcore::create_object_type(loader, ir, self, "Pcore::#{simple_name}Type", "Pcore::#{parent_name}", attributes_hash)
end

.register_ptypes(loader, ir) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/puppet/pops/types/types.rb', line 61

def self.register_ptypes(loader, ir)
  types = []
  Types.constants.each do |c|
    cls = Types.const_get(c)
    next unless cls.is_a?(Class) && cls < self
    type = cls.register_ptype(loader, ir)
    types << type unless type.nil?
  end
  tp = TypeParser.singleton
  types.each { |type| type.resolve(tp, loader) }
end