class Puppet::Pops::Loader::DependencyLoader

DependencyLoader

This loader provides visibility into a set of other loaders. It is used as a child of a ModuleLoader (or other loader) to make its direct dependencies visible for loading from contexts that have access to this dependency loader. Access is typically given to logic that resides inside of the module, but not to those that just depend on the module.

It is instantiated with a name, and with a set of dependency_loaders.

@api private

Attributes

index[R]

An index of module_name to module loader used to speed up lookup of qualified names

Public Class Methods

new(parent_loader, name, dependency_loaders, environment) click to toggle source

Creates a DependencyLoader for one parent loader

@param parent_loader [Puppet::Pops::Loader] typically a module loader for the root @param name [String] the name of the dependency-loader (used for debugging and tracing only) @param dependency_loaders [Array<Puppet::Pops::Loader>] array of loaders for modules this module depends on

Calls superclass method Puppet::Pops::Loader::BaseLoader::new
   # File lib/puppet/pops/loader/dependency_loader.rb
21 def initialize(parent_loader, name, dependency_loaders, environment)
22   super(parent_loader, name, environment)
23   @dependency_loaders = dependency_loaders
24 end

Public Instance Methods

discover(type, error_collector = nil, name_authority = Puppet::Pops::Pcore::RUNTIME_NAME_AUTHORITY, &block) click to toggle source
   # File lib/puppet/pops/loader/dependency_loader.rb
26 def discover(type, error_collector = nil, name_authority = Puppet::Pops::Pcore::RUNTIME_NAME_AUTHORITY, &block)
27   result = []
28   @dependency_loaders.each { |loader| result.concat(loader.discover(type, error_collector, name_authority, &block)) }
29   result.concat(super)
30   result
31 end
find(typed_name) click to toggle source

Finds name in a loader this loader depends on / can see

   # File lib/puppet/pops/loader/dependency_loader.rb
35 def find(typed_name)
36   if typed_name.qualified?
37     l = index()[typed_name.name_parts[0]]
38     if l
39       l.load_typed(typed_name)
40     else
41       # no module entered as dependency with name matching first segment of wanted name
42       nil
43     end
44   else
45     # a non name-spaced name, have to search since it can be anywhere.
46     # (Note: superclass caches the result in this loader as it would have to repeat this search for every
47     # lookup otherwise).
48     loaded = @dependency_loaders.reduce(nil) do |previous, loader|
49       break previous if !previous.nil?
50       loader.load_typed(typed_name)
51     end
52     if loaded
53       promote_entry(loaded)
54     end
55     loaded
56   end
57 end
loaded_entry(typed_name, check_dependencies = false) click to toggle source

@api public

   # File lib/puppet/pops/loader/dependency_loader.rb
61 def loaded_entry(typed_name, check_dependencies = false)
62   super || (check_dependencies ? loaded_entry_in_dependency(typed_name, check_dependencies) : nil)
63 end
to_s() click to toggle source
   # File lib/puppet/pops/loader/dependency_loader.rb
65 def to_s
66   "(DependencyLoader '#{@loader_name}' [" + @dependency_loaders.map {|loader| loader.to_s }.join(' ,') + "])"
67 end

Private Instance Methods

loaded_entry_in_dependency(typed_name, check_dependencies) click to toggle source
   # File lib/puppet/pops/loader/dependency_loader.rb
71 def loaded_entry_in_dependency(typed_name, check_dependencies)
72   if typed_name.qualified?
73     l = index[typed_name.name_parts[0]]
74     if l
75       l.loaded_entry(typed_name)
76     else
77       # no module entered as dependency with name matching first segment of wanted name
78       nil
79     end
80   else
81     # a non name-spaced name, have to search since it can be anywhere.
82     # (Note: superclass caches the result in this loader as it would have to repeat this search for every
83     # lookup otherwise).
84     @dependency_loaders.reduce(nil) do |previous, loader|
85       break previous if !previous.nil?
86       loader.loaded_entry(typed_name, check_dependencies)
87     end
88   end
89 end