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

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

Runtime3TypeLoader

Loads a resource type using the 3.x type loader

Constant Summary

Constants inherited from Loader

Loader::LOADABLE_KINDS

Instance Attribute Summary

Attributes inherited from BaseLoader

#parent

Attributes inherited from Loader

#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

Constructor Details

#initialize(parent_loader, loaders, environment, env_path) ⇒ 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


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

def initialize(parent_loader, loaders, environment, env_path)
  super(parent_loader, environment.name)
  @environment = environment
  @resource_3x_loader = env_path.nil? ? nil : ModuleLoaders.pcore_resource_type_loader_from(parent_loader, loaders, env_path)
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.


95
96
97
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 95

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.


16
17
18
19
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 16

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


29
30
31
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
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 29

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.


21
22
23
# File 'lib/puppet/pops/loader/runtime3_type_loader.rb', line 21

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