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
445 def initialize(parent_loader, loaders, module_name, path, loader_name, loadables = LOADABLE_KINDS)
446   super
447   @path_index = Set.new
448 end

Public Instance Methods

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