Class: Puppet::Pops::Loader::ModuleLoaders::FileBased Private

Inherits:
AbstractPathBasedModuleLoader show all
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

GemBased

Instance Attribute Summary collapse

Attributes inherited from AbstractPathBasedModuleLoader

#module_name, #path, #private_loader

Attributes inherited from BaseLoader

#loader_name, #parent

Instance Method Summary collapse

Methods inherited from AbstractPathBasedModuleLoader

#find, #get_source_ref

Methods inherited from BaseLoader

#add_entry, #get_entry, #load_typed, #promote_entry, #set_entry

Methods inherited from Loader

#[], #find, #get_entry, #load, #load_typed, #parent, #private_loader, #set_entry

Constructor Details

#initialize(parent_loader, loaders, module_name, path, loader_name) ⇒ 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)

Parameters:

  • parent_loader (Puppet::Pops::Loader::Loader)

    typically the loader for the environment or root

  • module_name (String)

    the name of the module (non qualified name), may be nil for “modules” only containing globals

  • path (String)

    the path to the root of the module (semantics defined by subclass)

  • loader_name (String)

    a name that identifies the loader



179
180
181
182
183
184
185
# File 'lib/puppet/pops/loader/module_loaders.rb', line 179

def initialize(parent_loader, loaders, module_name, path, loader_name)
  super
  unless Puppet::FileSystem.directory?(path)
    raise ArgumentError, "The given module root path '#{path}' is not a directory (required for file system based module path entry)"
  end
  @path_index = Set.new()
end

Instance Attribute Details

#path_indexObject (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.



170
171
172
# File 'lib/puppet/pops/loader/module_loaders.rb', line 170

def path_index
  @path_index
end

#smart_pathsObject (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.



169
170
171
# File 'lib/puppet/pops/loader/module_loaders.rb', line 169

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.



200
201
202
203
204
# File 'lib/puppet/pops/loader/module_loaders.rb', line 200

def add_to_index(smart_path)
  found = Dir.glob(File.join(smart_path.generic_path, '**', "*#{smart_path.extension}"))
  @path_index.merge(found)
  found
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.



187
188
189
190
# File 'lib/puppet/pops/loader/module_loaders.rb', line 187

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.



206
207
208
# File 'lib/puppet/pops/loader/module_loaders.rb', line 206

def get_contents(effective_path)
  Puppet::FileSystem.read(effective_path)
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.

Returns:

  • (Boolean)


192
193
194
# File 'lib/puppet/pops/loader/module_loaders.rb', line 192

def meaningful_to_search?(smart_path)
  ! add_to_index(smart_path).empty?
end

#to_sObject

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.



196
197
198
# File 'lib/puppet/pops/loader/module_loaders.rb', line 196

def to_s()
  "(ModuleLoader::FileBased '#{loader_name()}' '#{module_name()}')"
end