Class: Puppet::Pops::Types::PMetaType Private

Inherits:
PAnyType show all
Includes:
Annotatable
Defined in:
lib/puppet/pops/types/p_meta_type.rb

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

Direct Known Subclasses

PObjectType, PTypeSetType

Constant Summary

Constants included from Annotatable

Annotatable::TYPE_ANNOTATIONS

Constants inherited from PAnyType

Puppet::Pops::Types::PAnyType::DEFAULT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Annotatable

#_pcore_init_hash, #annotatable_accept, #annotations, #init_annotatable

Methods inherited from PAnyType

#==, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, create, #create, #eql?, #generalize, #hash, #iterable?, #iterable_type, #kind_of_callable?, #name, new_function, #new_function, #normalize, #really_instance?, #roundtrip_with_string?, simple_name, #simple_name, #to_alias_expanded_s

Methods inherited from TypedModelObject

_pcore_type, create_ptype, register_ptypes

Methods included from PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type

Instance Attribute Details

#loaderObject (readonly)

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.



13
14
15
# File 'lib/puppet/pops/types/p_meta_type.rb', line 13

def loader
  @loader
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object

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.



15
16
17
# File 'lib/puppet/pops/types/p_meta_type.rb', line 15

def self.register_ptype(loader, ir)
  # Abstract type. It doesn't register anything
end

Instance Method Details

#accept(visitor, guard) ⇒ Object

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.



19
20
21
22
# File 'lib/puppet/pops/types/p_meta_type.rb', line 19

def accept(visitor, guard)
  annotatable_accept(visitor, guard)
  super
end

#instance?(o, guard = nil) ⇒ Boolean

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.

Returns:

  • (Boolean)


24
25
26
# File 'lib/puppet/pops/types/p_meta_type.rb', line 24

def instance?(o, guard = nil)
  assignable?(TypeCalculator.infer(o), guard)
end

#resolve(loader) ⇒ PTypeAliasType

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.

Called from the TypeParser once it has found a type using the Loader. The TypeParser will interpret the contained expression and the resolved type is remembered. This method also checks and remembers if the resolve type contains self recursion.

Parameters:

  • type_parser (TypeParser)

    type parser that will interpret the type expression

  • loader (Loader::Loader)

    loader to use when loading type aliases

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/puppet/pops/types/p_meta_type.rb', line 36

def resolve(loader)
  unless @init_hash_expression.nil?
    @loader = loader
    @self_recursion = true # assumed while it being found out below

    init_hash_expression = @init_hash_expression
    @init_hash_expression = nil
    if init_hash_expression.is_a?(Model::LiteralHash)
      init_hash = resolve_literal_hash(loader, init_hash_expression)
    else
      init_hash = resolve_hash(loader, init_hash_expression)
    end
    _pcore_init_from_hash(init_hash)

    # Find out if this type is recursive. A recursive type has performance implications
    # on several methods and this knowledge is used to avoid that for non-recursive
    # types.
    guard = RecursionGuard.new
    accept(NoopTypeAcceptor::INSTANCE, guard)
    @self_recursion = guard.recursive_this?(self)
  end
  self
end

#resolve_hash(loader, init_hash) ⇒ Object

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.



64
65
66
# File 'lib/puppet/pops/types/p_meta_type.rb', line 64

def resolve_hash(loader, init_hash)
  resolve_type_refs(loader, init_hash)
end

#resolve_literal_hash(loader, init_hash_expression) ⇒ Object

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.



60
61
62
# File 'lib/puppet/pops/types/p_meta_type.rb', line 60

def resolve_literal_hash(loader, init_hash_expression)
  TypeParser.singleton.interpret_LiteralHash(init_hash_expression, loader)
end

#resolve_type_refs(loader, o) ⇒ Object

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.



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/puppet/pops/types/p_meta_type.rb', line 68

def resolve_type_refs(loader, o)
  case o
  when Hash
    Hash[o.map { |k, v| [resolve_type_refs(loader, k), resolve_type_refs(loader, v)] }]
  when Array
    o.map { |e| resolve_type_refs(loader, e) }
  when PAnyType
    o.resolve(loader)
  else
    o
  end
end

#to_sString

Returns the expanded string the form of the alias, e.g. <alias name> = <resolved type>

Returns:

  • (String)

    the expanded form of this alias



85
86
87
# File 'lib/puppet/pops/types/p_meta_type.rb', line 85

def to_s
  TypeFormatter.singleton.alias_expanded_string(self)
end