module Puppet::Pops::Loader::ModuleLoaders

ModuleLoaders

A ModuleLoader loads items from a single module. The ModuleLoaders (ruby) module contains various such loaders. There is currently one concrete implementation, ModuleLoaders::FileBased that loads content from the file system. Other implementations can be created - if they are based on name to path mapping where the path is relative to a root path, they can derive the base behavior from the ModuleLoaders::AbstractPathBasedModuleLoader class.

Examples of such extensions could be a zip/jar/compressed file base loader.

Notably, a ModuleLoader does not configure itself - it is given the information it needs (the root, its name etc.) Logic higher up in the loader hierarchy of things makes decisions based on the “shape of modules”, and “available modules” to determine which module loader to use for each individual module. (There could be differences in internal layout etc.)

A module loader is also not aware of the mapping of name to relative paths.

@api private

Constants

NAMESPACE_WILDCARD

Wildcard module name for module loaders, makes loading possible from any namespace.

Public Class Methods

cached_loader_from(parent_loader, loaders) click to toggle source

This is exactly the same as the system_loader_from method, but the argument for path is changed to location where pluginsync stores functions. It also accepts definitions in any namespace since pluginsync places all of them in the same directory.

   # File lib/puppet/pops/loader/module_loaders.rb
30 def self.cached_loader_from(parent_loader, loaders)
31   LibRootedFileBased.new(parent_loader,
32     loaders,
33     NAMESPACE_WILDCARD,
34     Puppet[:libdir],
35     'cached_puppet_lib',
36     [:func_4x, :func_3x, :datatype]
37   )
38 end
environment_loader_from(parent_loader, loaders, env_path) click to toggle source
   # File lib/puppet/pops/loader/module_loaders.rb
56 def self.environment_loader_from(parent_loader, loaders, env_path)
57   if env_path.nil? || env_path.empty?
58     EmptyLoader.new(parent_loader, ENVIRONMENT, loaders.environment)
59   else
60     FileBased.new(parent_loader,
61       loaders,
62       ENVIRONMENT,
63       env_path,
64       ENVIRONMENT
65     )
66   end
67 end
module_loader_from(parent_loader, loaders, module_name, module_path) click to toggle source
   # File lib/puppet/pops/loader/module_loaders.rb
69 def self.module_loader_from(parent_loader, loaders, module_name, module_path)
70   ModuleLoaders::FileBased.new(parent_loader,
71                                                      loaders,
72                                                      module_name,
73                                                      module_path,
74                                                      module_name
75                                                      )
76 end
pcore_resource_type_loader_from(parent_loader, loaders, environment_path) click to toggle source
   # File lib/puppet/pops/loader/module_loaders.rb
78 def self.pcore_resource_type_loader_from(parent_loader, loaders, environment_path)
79   ModuleLoaders::FileBased.new(parent_loader,
80     loaders,
81     nil,
82     environment_path,
83     'pcore_resource_types'
84   )
85 end
system_loader_from(parent_loader, loaders) click to toggle source
   # File lib/puppet/pops/loader/module_loaders.rb
40 def self.system_loader_from(parent_loader, loaders)
41   # Puppet system may be installed in a fixed location via RPM, installed as a Gem, via source etc.
42   # The only way to find this across the different ways puppet can be installed is
43   # to search up the path from this source file's __FILE__ location until it finds the base of
44   # puppet.
45   #
46   puppet_lib = File.realpath(File.join(File.dirname(__FILE__), '../../..'))
47   LibRootedFileBased.new(parent_loader,
48                          loaders,
49                          nil,
50                          puppet_lib,   # may or may not have a 'lib' above 'puppet'
51                          'puppet_system',
52                          [:func_4x, :func_3x, :datatype]   # only load ruby functions and types from "puppet"
53                         )
54 end