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

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

Overview

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.

API:

  • private

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.

API:

  • private



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

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.

API:

  • private



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

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.

API:

  • private



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

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:

Raises:

API:

  • private



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

def instance?(o, guard = nil)
  raise NotImplementedError, "Subclass of PMetaType should implement 'instance?'"
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 that will interpret the type expression

  • loader to use when loading type aliases

Returns:

  • the receiver of the call, i.e. self

API:

  • private



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

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.

API:

  • private



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

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.

API:

  • private



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

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.

API:

  • private



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

def resolve_type_refs(loader, o)
  case o
  when Hash
    o.to_h { |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

#resolved?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:

API:

  • private



82
83
84
# File 'lib/puppet/pops/types/p_meta_type.rb', line 82

def resolved?
  @init_hash_expression.nil?
end

#to_sString

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

Returns:

  • the expanded form of this alias

API:

  • public



90
91
92
# File 'lib/puppet/pops/types/p_meta_type.rb', line 90

def to_s
  TypeFormatter.singleton.alias_expanded_string(self)
end