MMCT TEAM
Server IP : 111.118.215.189  /  Your IP : 18.216.95.250
Web Server : Apache
System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : a1673wkz ( 2475)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/share/ruby/vendor_ruby/puppet/pops/loader/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/share/ruby/vendor_ruby/puppet/pops/loader/dependency_loader.rb
# =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
#
class Puppet::Pops::Loader::DependencyLoader < Puppet::Pops::Loader::BaseLoader

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

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

  # Finds name in a loader this loader depends on / can see
  #
  def find(typed_name)
    if typed_name.qualified
      if loader = index()[typed_name.name_parts[0]]
        loader.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

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

  private

  def index()
    @index ||= @dependency_loaders.reduce({}) { |index, loader| index[loader.module_name] = loader; index }
  end
end

MMCT - 2023