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

#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

Constructor Details

#initialize(parent_loader, name, dependency_loaders) ⇒ 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


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

def initialize(parent_loader, name, dependency_loaders)
  super parent_loader, name
  @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.


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

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


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

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 if !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


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

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.


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

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