Class: Puppet::Pops::Loader::ModuleLoaders::FileBased Private
- Inherits:
-
AbstractPathBasedModuleLoader
- Object
- Loader
- BaseLoader
- AbstractPathBasedModuleLoader
- Puppet::Pops::Loader::ModuleLoaders::FileBased
- Defined in:
- lib/puppet/pops/loader/module_loaders.rb
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.
Direct Known Subclasses
Constant Summary
Constants inherited from Loader
Instance Attribute Summary collapse
- #path_index ⇒ Object readonly private
- #smart_paths ⇒ Object readonly private
Attributes inherited from AbstractPathBasedModuleLoader
#module_name, #path, #private_loader
Attributes inherited from BaseLoader
Attributes inherited from Loader
Instance Method Summary collapse
- #add_to_index(smart_path) ⇒ Object private
- #candidate_paths(effective_path) ⇒ Object private
- #existing_path(effective_path) ⇒ Object private
- #get_contents(effective_path) ⇒ Object private
-
#initialize(parent_loader, loaders, module_name, path, loader_name, loadables = LOADABLE_KINDS) ⇒ FileBased
constructor
private
Create a kind of ModuleLoader for one module (Puppet Module, or module like).
- #meaningful_to_search?(smart_path) ⇒ Boolean private
-
#relative_paths(smart_path) ⇒ Array<String>
private
Return all paths that matches the given smart path.
- #to_s ⇒ Object private
Methods inherited from AbstractPathBasedModuleLoader
#discover, #find, #get_source_ref, #global?, #instantiate, #lib_root?, #loadables
Methods inherited from BaseLoader
#add_entry, #discover, #get_entry, #load_typed, #loaded_entry, #promote_entry, #remove_entry, #set_entry
Methods inherited from Loader
#[], #discover, #find, #get_entry, #inspect, #load, #load_typed, #loadables, #loaded_entry, #parent, #private_loader, #set_entry, #synchronize
Constructor Details
#initialize(parent_loader, loaders, module_name, path, loader_name, loadables = LOADABLE_KINDS) ⇒ FileBased
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.
Create a kind of ModuleLoader for one module (Puppet Module, or module like)
445 446 447 448 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 445 def initialize(parent_loader, loaders, module_name, path, loader_name, loadables = LOADABLE_KINDS) super @path_index = Set.new end |
Instance Attribute Details
#path_index ⇒ Object (readonly)
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.
436 437 438 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 436 def path_index @path_index end |
#smart_paths ⇒ Object (readonly)
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.
435 436 437 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 435 def smart_paths @smart_paths end |
Instance Method Details
#add_to_index(smart_path) ⇒ 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.
479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 479 def add_to_index(smart_path) found = Dir.glob(File.join(smart_path.generic_path, '**', "*#{smart_path.extension}")) # The reason for not always rejecting directories here is performance (avoid extra stat calls). The # false positives (directories with a matching extension) is an error in any case and will be caught # later. found = found.reject { |file_name| File.directory?(file_name) } if smart_path.extension.empty? @path_index.merge(found) found end |
#candidate_paths(effective_path) ⇒ 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.
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 455 def candidate_paths(effective_path) basename = File.basename(effective_path, '.*') dirname = File.dirname(effective_path) files = @path_index.select do |path| File.dirname(path) == dirname end # At least one file has to match what we're loading, or it certainly doesn't exist if files.any? { |file| File.basename(file, '.*') == basename } files else [] end end |
#existing_path(effective_path) ⇒ 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.
450 451 452 453 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 450 def existing_path(effective_path) # Optimized, checks index instead of visiting file system @path_index.include?(effective_path) ? effective_path : nil end |
#get_contents(effective_path) ⇒ 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.
491 492 493 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 491 def get_contents(effective_path) Puppet::FileSystem.read(effective_path, :encoding => 'utf-8') end |
#meaningful_to_search?(smart_path) ⇒ Boolean
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.
471 472 473 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 471 def meaningful_to_search?(smart_path) ! add_to_index(smart_path).empty? end |
#relative_paths(smart_path) ⇒ Array<String>
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.
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
502 503 504 505 506 507 508 509 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 502 def relative_paths(smart_path) root = smart_path.generic_path found = [] @path_index.each do |path| found << Pathname(path).relative_path_from(Pathname(root)).to_s if smart_path.valid_path?(path) end found end |
#to_s ⇒ 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.
475 476 477 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 475 def to_s() "(ModuleLoader::FileBased '#{loader_name}' '#{module_name}')" end |