class Puppet::Pops::Loader::ModuleLoaders::FileBased

@api private

Attributes

path_index[R]
smart_paths[R]

Public Class Methods

new(parent_loader, loaders, module_name, path, loader_name, loadables = LOADABLE_KINDS) click to toggle source

Create a kind of ModuleLoader for one module (Puppet Module, or module like)

@param parent_loader [Loader] typically the loader for the environment or root @param module_name [String] the name of the module (non qualified name), may be nil for “modules” only containing globals @param path [String] the path to the root of the module (semantics defined by subclass) @param loader_name [String] a name that identifies the loader

    # File lib/puppet/pops/loader/module_loaders.rb
444 def initialize(parent_loader, loaders, module_name, path, loader_name, loadables = LOADABLE_KINDS)
445   super
446   @path_index = Set.new
447 end

Public Instance Methods

add_to_index(smart_path) click to toggle source
    # File lib/puppet/pops/loader/module_loaders.rb
478 def add_to_index(smart_path)
479   found = Dir.glob(File.join(smart_path.generic_path, '**', "*#{smart_path.extension}"))
480 
481   # The reason for not always rejecting directories here is performance (avoid extra stat calls). The
482   # false positives (directories with a matching extension) is an error in any case and will be caught
483   # later.
484   found = found.reject { |file_name| File.directory?(file_name) } if smart_path.extension.empty?
485 
486   @path_index.merge(found)
487   found
488 end
candidate_paths(effective_path) click to toggle source
    # File lib/puppet/pops/loader/module_loaders.rb
454 def candidate_paths(effective_path)
455   basename = File.basename(effective_path, '.*')
456   dirname = File.dirname(effective_path)
457 
458   files = @path_index.select do |path|
459     File.dirname(path) == dirname
460   end
461 
462   # At least one file has to match what we're loading, or it certainly doesn't exist
463   if files.any? { |file| File.basename(file, '.*') == basename }
464     files
465   else
466     []
467   end
468 end
existing_path(effective_path) click to toggle source
    # File lib/puppet/pops/loader/module_loaders.rb
449 def existing_path(effective_path)
450   # Optimized, checks index instead of visiting file system
451   @path_index.include?(effective_path) ? effective_path : nil
452 end
get_contents(effective_path) click to toggle source
    # File lib/puppet/pops/loader/module_loaders.rb
490 def get_contents(effective_path)
491   Puppet::FileSystem.read(effective_path, :encoding => 'utf-8')
492 end
meaningful_to_search?(smart_path) click to toggle source
    # File lib/puppet/pops/loader/module_loaders.rb
470 def meaningful_to_search?(smart_path)
471   ! add_to_index(smart_path).empty?
472 end
relative_paths(smart_path) click to toggle source

Return all paths that matches the given smart path. The returned paths are relative to the `#generic_path` of the given smart path.

This method relies on the cache and does not perform any file system access

@param smart_path [SmartPath] the path to find relative paths for @return [Array<String>] found paths

    # File lib/puppet/pops/loader/module_loaders.rb
501 def relative_paths(smart_path)
502   root = smart_path.generic_path
503   found = []
504   @path_index.each do |path|
505     found << Pathname(path).relative_path_from(Pathname(root)).to_s if smart_path.valid_path?(path)
506   end
507   found
508 end
to_s() click to toggle source
    # File lib/puppet/pops/loader/module_loaders.rb
474 def to_s()
475   "(ModuleLoader::FileBased '#{loader_name}' '#{module_name}')"
476 end