Class: Puppet::Pops::Loader::DependencyLoader Private

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

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.

Constant Summary

Constants inherited from Loader

Loader::LOADABLE_KINDS

Instance Attribute Summary

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, #promote_entry, #remove_entry, #set_entry

Methods inherited from Loader

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

Constructor Details

#initialize(parent_loader, name, dependency_loaders, environment) ⇒ DependencyLoader

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.

Creates a DependencyLoader for one parent loader

Parameters:

  • parent_loader (Puppet::Pops::Loader)

    typically a module loader for the root

  • name (String)

    the name of the dependency-loader (used for debugging and tracing only)

  • dependency_loaders (Array<Puppet::Pops::Loader>)

    array of loaders for modules this module depends on



19
20
21
22
# File 'lib/puppet/pops/loader/dependency_loader.rb', line 19

def initialize(parent_loader, name, dependency_loaders, environment)
  super(parent_loader, name, environment)
  @dependency_loaders = dependency_loaders
end

Instance Method Details

#discover(type, error_collector = nil, name_authority = Puppet::Pops::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.



24
25
26
27
28
29
# File 'lib/puppet/pops/loader/dependency_loader.rb', line 24

def discover(type, error_collector = nil, name_authority = Puppet::Pops::Pcore::RUNTIME_NAME_AUTHORITY, &block)
  result = []
  @dependency_loaders.each { |loader| result.concat(loader.discover(type, error_collector, name_authority, &block)) }
  result.concat(super)
  result
end

#find(typed_name) ⇒ 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.

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/puppet/pops/loader/dependency_loader.rb', line 33

def find(typed_name)
  if typed_name.qualified?
    l = index()[typed_name.name_parts[0]]
    if l
      l.load_typed(typed_name)
    else
      # no module entered as dependency with name matching first segment of wanted name
      nil
    end
  else
    # a non name-spaced name, have to search since it can be anywhere.
    # (Note: superclass caches the result in this loader as it would have to repeat this search for every
    # lookup otherwise).
    loaded = @dependency_loaders.reduce(nil) do |previous, loader|
      break previous unless previous.nil?

      loader.load_typed(typed_name)
    end
    if loaded
      promote_entry(loaded)
    end
    loaded
  end
end

#loaded_entry(typed_name, check_dependencies = false) ⇒ Object



60
61
62
# File 'lib/puppet/pops/loader/dependency_loader.rb', line 60

def loaded_entry(typed_name, check_dependencies = false)
  super || (check_dependencies ? loaded_entry_in_dependency(typed_name, check_dependencies) : nil)
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.



64
65
66
# File 'lib/puppet/pops/loader/dependency_loader.rb', line 64

def to_s
  "(DependencyLoader '#{@loader_name}' [" + @dependency_loaders.map(&:to_s).join(' ,') + "])"
end