class Puppet::Pops::Loader::Runtime3TypeLoader

Runtime3TypeLoader

Loads a resource type using the 3.x type loader

@api private

Attributes

resource_3x_loader[R]

Public Class Methods

new(parent_loader, loaders, environment, resource_3x_loader) click to toggle source
Calls superclass method
   # File lib/puppet/pops/loader/runtime3_type_loader.rb
13 def initialize(parent_loader, loaders, environment, resource_3x_loader)
14   super(parent_loader, environment.name, environment)
15   @environment = environment
16   @resource_3x_loader = resource_3x_loader
17 end

Public Instance Methods

allow_shadowing?() click to toggle source

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.

    # File lib/puppet/pops/loader/runtime3_type_loader.rb
 98 def allow_shadowing?
 99   true
100 end
discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block) click to toggle source
   # File lib/puppet/pops/loader/runtime3_type_loader.rb
19 def discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block)
20   # TODO: Use generated index of all known types (requires separate utility).
21   parent.discover(type, error_collector, name_authority, &block)
22 end
find(typed_name) click to toggle source

Finds typed/named entity in this module @param typed_name [TypedName] the type/name to find @return [Loader::NamedEntry, nil found/created entry, or nil if not found

   # File lib/puppet/pops/loader/runtime3_type_loader.rb
32 def find(typed_name)
33   return nil unless typed_name.name_authority == Pcore::RUNTIME_NAME_AUTHORITY
34   case typed_name.type
35   when :type
36     value = nil
37     name = typed_name.name
38     if @resource_3x_loader.nil?
39       value = Puppet::Type.type(name) unless typed_name.qualified?
40       if value.nil?
41         # Look for a user defined type
42         value = @environment.known_resource_types.find_definition(name)
43       end
44     else
45       impl_te = find_impl(TypedName.new(:resource_type_pp, name, typed_name.name_authority))
46       value = impl_te.value unless impl_te.nil?
47     end
48 
49     if value.nil?
50       # Cache the fact that it wasn't found
51       set_entry(typed_name, nil)
52       return nil
53     end
54 
55     # Loaded types doesn't have the same life cycle as this loader, so we must start by
56     # checking if the type was created. If it was, an entry will already be stored in
57     # this loader. If not, then it was created before this loader was instantiated and
58     # we must therefore add it.
59     te = get_entry(typed_name)
60     te = set_entry(typed_name, Types::TypeFactory.resource(value.name.to_s)) if te.nil? || te.value.nil?
61     te
62   when :resource_type_pp
63     @resource_3x_loader.nil? ? nil : find_impl(typed_name)
64   else
65     nil
66   end
67 end
to_s() click to toggle source
   # File lib/puppet/pops/loader/runtime3_type_loader.rb
24 def to_s()
25   "(Runtime3TypeLoader '#{loader_name()}')"
26 end

Private Instance Methods

find_impl(typed_name) click to toggle source

Find the implementation for the resource type by first consulting the internal loader for pp defined 'Puppet::Resource::ResourceType3' instances, then check for a Puppet::Type and lastly check for a defined type.

   # File lib/puppet/pops/loader/runtime3_type_loader.rb
72 def find_impl(typed_name)
73   name = typed_name.name
74   te = StaticLoader::BUILTIN_TYPE_NAMES_LC.include?(name) ? nil : @resource_3x_loader.load_typed(typed_name)
75   if te.nil? || te.value.nil?
76     # Look for Puppet::Type
77     value = Puppet::Type.type(name) unless typed_name.qualified?
78     if value.nil?
79       # Look for a user defined type
80       value = @environment.known_resource_types.find_definition(name)
81       if value.nil?
82         # Cache the fact that it wasn't found
83         @resource_3x_loader.set_entry(typed_name, nil)
84         return nil
85       end
86     end
87     te = @resource_3x_loader.get_entry(typed_name)
88     te = @resource_3x_loader.set_entry(typed_name, value) if te.nil? || te.value.nil?
89   end
90   te
91 end