Class: Puppet::Pops::Loader::Runtime3TypeLoader Private

Inherits:
BaseLoader show all
Defined in:
lib/puppet/pops/loader/runtime3_type_loader.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.

Constant Summary

Constants inherited from Loader

Loader::LOADABLE_KINDS

Instance Attribute Summary collapse

Attributes inherited from BaseLoader

#parent

Attributes inherited from Loader

#environment, #loader_name

Instance Method Summary collapse

Methods inherited from BaseLoader

#add_entry, #get_entry, #load_typed, #loaded_entry, #promote_entry, #remove_entry, #set_entry

Methods inherited from Loader

#[], #get_entry, #inspect, #load, #load_typed, #loadables, #loaded_entry, #parent, #private_loader, #set_entry, #synchronize

Constructor Details

#initialize(parent_loader, loaders, environment, resource_3x_loader) ⇒ Runtime3TypeLoader

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 a new instance of Runtime3TypeLoader.



13
14
15
16
17
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 13

def initialize(parent_loader, loaders, environment, resource_3x_loader)
  super(parent_loader, environment.name, environment)
  @environment = environment
  @resource_3x_loader = resource_3x_loader
end

Instance Attribute Details

#resource_3x_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.



11
12
13
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 11

def resource_3x_loader
  @resource_3x_loader
end

Instance Method Details

#allow_shadowing?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.

Allows shadowing since this loader is populated with all loaded resource types at time of loading. This loading will, for built in types override the aliases configured in the static loader.

Returns:

  • (Boolean)


99
100
101
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 99

def allow_shadowing?
  true
end

#discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block) ⇒ 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/loader/runtime3_type_loader.rb', line 19

def discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block)
  # TODO: Use generated index of all known types (requires separate utility).
  parent.discover(type, error_collector, name_authority, &block)
end

#find(typed_name) ⇒ Loader::NamedEntry, ...

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.

Finds typed/named entity in this module

Parameters:

  • typed_name (TypedName)

    the type/name to find

Returns:

  • (Loader::NamedEntry, nil found/created entry, or nil if not found)

    Loader::NamedEntry, nil found/created entry, or nil if not found



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 32

def find(typed_name)
  return nil unless typed_name.name_authority == Pcore::RUNTIME_NAME_AUTHORITY

  case typed_name.type
  when :type
    value = nil
    name = typed_name.name
    if @resource_3x_loader.nil?
      value = Puppet::Type.type(name) unless typed_name.qualified?
      if value.nil?
        # Look for a user defined type
        value = @environment.known_resource_types.find_definition(name)
      end
    else
      impl_te = find_impl(TypedName.new(:resource_type_pp, name, typed_name.name_authority))
      value = impl_te.value unless impl_te.nil?
    end

    if value.nil?
      # Cache the fact that it wasn't found
      set_entry(typed_name, nil)
      return nil
    end

    # Loaded types doesn't have the same life cycle as this loader, so we must start by
    # checking if the type was created. If it was, an entry will already be stored in
    # this loader. If not, then it was created before this loader was instantiated and
    # we must therefore add it.
    te = get_entry(typed_name)
    te = set_entry(typed_name, Types::TypeFactory.resource(value.name.to_s)) if te.nil? || te.value.nil?
    te
  when :resource_type_pp
    @resource_3x_loader.nil? ? nil : find_impl(typed_name)
  else
    nil
  end
end

#to_sObject

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.



24
25
26
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 24

def to_s
  "(Runtime3TypeLoader '#{loader_name()}')"
end