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
12 def initialize(parent_loader, loaders, environment, resource_3x_loader)
13   super(parent_loader, environment.name, environment)
14   @environment = environment
15   @resource_3x_loader = resource_3x_loader
16 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
97 def allow_shadowing?
98   true
99 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
18 def discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block)
19   # TODO: Use generated index of all known types (requires separate utility).
20   parent.discover(type, error_collector, name_authority, &block)
21 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
31 def find(typed_name)
32   return nil unless typed_name.name_authority == Pcore::RUNTIME_NAME_AUTHORITY
33   case typed_name.type
34   when :type
35     value = nil
36     name = typed_name.name
37     if @resource_3x_loader.nil?
38       value = Puppet::Type.type(name) unless typed_name.qualified?
39       if value.nil?
40         # Look for a user defined type
41         value = @environment.known_resource_types.find_definition(name)
42       end
43     else
44       impl_te = find_impl(TypedName.new(:resource_type_pp, name, typed_name.name_authority))
45       value = impl_te.value unless impl_te.nil?
46     end
47 
48     if value.nil?
49       # Cache the fact that it wasn't found
50       set_entry(typed_name, nil)
51       return nil
52     end
53 
54     # Loaded types doesn't have the same life cycle as this loader, so we must start by
55     # checking if the type was created. If it was, an entry will already be stored in
56     # this loader. If not, then it was created before this loader was instantiated and
57     # we must therefore add it.
58     te = get_entry(typed_name)
59     te = set_entry(typed_name, Types::TypeFactory.resource(value.name.to_s)) if te.nil? || te.value.nil?
60     te
61   when :resource_type_pp
62     @resource_3x_loader.nil? ? nil : find_impl(typed_name)
63   else
64     nil
65   end
66 end
to_s() click to toggle source
   # File lib/puppet/pops/loader/runtime3_type_loader.rb
23 def to_s()
24   "(Runtime3TypeLoader '#{loader_name()}')"
25 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
71 def find_impl(typed_name)
72   name = typed_name.name
73   te = StaticLoader::BUILTIN_TYPE_NAMES_LC.include?(name) ? nil : @resource_3x_loader.load_typed(typed_name)
74   if te.nil? || te.value.nil?
75     # Look for Puppet::Type
76     value = Puppet::Type.type(name) unless typed_name.qualified?
77     if value.nil?
78       # Look for a user defined type
79       value = @environment.known_resource_types.find_definition(name)
80       if value.nil?
81         # Cache the fact that it wasn't found
82         @resource_3x_loader.set_entry(typed_name, nil)
83         return nil
84       end
85     end
86     te = @resource_3x_loader.get_entry(typed_name)
87     te = @resource_3x_loader.set_entry(typed_name, value) if te.nil? || te.value.nil?
88   end
89   te
90 end