Class: Puppet::Pops::Loader::ModuleLoaders::AbstractPathBasedModuleLoader Private
- Inherits:
-
BaseLoader
- Object
- Loader
- BaseLoader
- Puppet::Pops::Loader::ModuleLoaders::AbstractPathBasedModuleLoader
- 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
Instance Attribute Summary collapse
-
#module_name ⇒ Object
readonly
private
The name of the module, or nil, if this is a global “component”.
-
#path ⇒ Object
readonly
private
The path to the location of the module/component - semantics determined by subclass.
-
#private_loader ⇒ Object
private
Produces the private loader for the module.
-
#smart_paths ⇒ Object
readonly
private
A map of type to smart-paths that help with minimizing the number of paths to scan.
Attributes inherited from BaseLoader
Instance Method Summary collapse
-
#existing_path(resolved_path) ⇒ Boolean
private
Abstract method that subclasses override to answer if the given relative path exists, and if so returns that path.
-
#find(typed_name) ⇒ Puppet::Pops::Loader::Loader::NamedEntry, ...
private
Finds typed/named entity in this module.
-
#get_contents(effective_path) ⇒ String
private
Abstract method that subclasses override to produce the content of the effective path.
-
#get_source_ref(relative_path) ⇒ String
private
Abstract method that subclasses override to produce a source reference String used to identify the system resource (resource in the URI sense).
-
#initialize(parent_loader, loaders, module_name, path, loader_name) ⇒ AbstractPathBasedModuleLoader
constructor
private
Initialize a kind of ModuleLoader for one module.
-
#meaningful_to_search?(smart_path) ⇒ Boolean
private
Abstract method that subclasses override that checks if it is meaningful to search using a generic smart path.
Methods inherited from BaseLoader
#add_entry, #get_entry, #load_typed, #promote_entry, #set_entry
Methods inherited from Loader
#[], #get_entry, #load, #load_typed, #parent, #set_entry
Constructor Details
#initialize(parent_loader, loaders, module_name, path, loader_name) ⇒ AbstractPathBasedModuleLoader
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.
Initialize a kind of ModuleLoader for one module
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 47 def initialize(parent_loader, loaders, module_name, path, loader_name) super parent_loader, loader_name # Irrespective of the path referencing a directory or file, the path must exist. unless Puppet::FileSystem.exist?(path) raise ArgumentError, "The given path '#{path}' does not exist!" end @module_name = module_name @path = path @smart_paths = Puppet::Pops::Loader::LoaderPaths::SmartPaths.new(self) @loaders = loaders end |
Instance Attribute Details
#module_name ⇒ 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.
The name of the module, or nil, if this is a global “component”
26 27 28 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 26 def module_name @module_name end |
#path ⇒ 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.
The path to the location of the module/component - semantics determined by subclass
29 30 31 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 29 def path @path end |
#private_loader ⇒ 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.
Produces the private loader for the module. If this module is not already resolved, this will trigger resolution
39 40 41 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 39 def private_loader @private_loader 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.
A map of type to smart-paths that help with minimizing the number of paths to scan
32 33 34 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 32 def smart_paths @smart_paths end |
Instance Method Details
#existing_path(resolved_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.
Abstract method that subclasses override to answer if the given relative path exists, and if so returns that path
134 135 136 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 134 def existing_path(resolved_path) raise NotImplementedError.new end |
#find(typed_name) ⇒ Puppet::Pops::Loader::Loader::NamedEntry, ...
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 typed/named entity in this module
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 65 def find(typed_name) # Assume it is a global name, and that all parts of the name should be used when looking up name_part_index = 0 name_parts = typed_name.name_parts # Certain types and names can be disqualified up front if name_parts.size > 1 # The name is in a name space. # Then entity cannot possible be in this module unless the name starts with the module name. # Note: If "module" represents a "global component", the module_name is nil and cannot match which is # ok since such a "module" cannot have namespaced content). # return nil unless name_parts[0] == module_name # Skip the first part of the name when computing the path since the path already contains the name of the # module name_part_index = 1 else # The name is in the global name space. # The only globally name-spaced elements that may be loaded from modules are functions and resource types case typed_name.type when :function when :resource_type else # anything else cannot possibly be in this module # TODO: should not be allowed anyway... may have to revisit this decision return nil end end # Get the paths that actually exist in this module (they are lazily processed once and cached). # The result is an array (that may be empty). # Find the file to instantiate, and instantiate the entity if file is found origin = nil if (smart_path = smart_paths.effective_paths(typed_name.type).find do |sp| origin = sp.effective_path(typed_name, name_part_index) existing_path(origin) end) value = smart_path.instantiator.create(self, typed_name, origin, get_contents(origin)) # cache the entry and return it set_entry(typed_name, value, origin) else nil end end |
#get_contents(effective_path) ⇒ 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.
Abstract method that subclasses override to produce the content of the effective path. It should either succeed and return a String or fail with an exception.
144 145 146 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 144 def get_contents(effective_path) raise NotImplementedError.new end |
#get_source_ref(relative_path) ⇒ 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.
Abstract method that subclasses override to produce a source reference String used to identify the system resource (resource in the URI sense).
154 155 156 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 154 def get_source_ref(relative_path) raise NotImplementedError.new 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.
Abstract method that subclasses override that checks if it is meaningful to search using a generic smart path. This optimization is performed to not be tricked into searching an empty directory over and over again. The implementation may perform a deep search for file content other than directories and cache this in and index. It is guaranteed that a call to meaningful_to_search? takes place before checking any other path with relative_path_exists?.
This optimization exists because many modules have been created from a template and they have empty directories for functions, types, etc. (It is also the place to create a cached index of the content).
125 126 127 |
# File 'lib/puppet/pops/loader/module_loaders.rb', line 125 def meaningful_to_search?(smart_path) raise NotImplementedError.new end |