Module: Puppet::Pops::Loader::ModuleLoaders Private

Defined in:
lib/puppet/pops/loader/module_loaders.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

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.

Defined Under Namespace

Classes: AbstractPathBasedModuleLoader, EmptyLoader, FileBased, GemBased, LibRootedFileBased

Constant Summary collapse

NAMESPACE_WILDCARD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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

'*'.freeze

Class Method Summary collapse

Class Method Details

.cached_loader_from(parent_loader, loaders) ⇒ 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.

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.


30
31
32
33
34
35
36
37
38
# File 'lib/puppet/pops/loader/module_loaders.rb', line 30

def self.cached_loader_from(parent_loader, loaders)
  LibRootedFileBased.new(parent_loader,
    loaders,
    NAMESPACE_WILDCARD,
    Puppet[:libdir],
    'cached_puppet_lib',
    [:func_4x, :func_3x, :datatype]
  )
end

.environment_loader_from(parent_loader, loaders, env_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.


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/puppet/pops/loader/module_loaders.rb', line 56

def self.environment_loader_from(parent_loader, loaders, env_path)
  if env_path.nil? || env_path.empty?
    EmptyLoader.new(parent_loader, ENVIRONMENT)
  else
    FileBased.new(parent_loader,
      loaders,
      ENVIRONMENT,
      env_path,
      ENVIRONMENT
    )
  end
end

.module_loader_from(parent_loader, loaders, module_name, module_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.


69
70
71
72
73
74
75
76
# File 'lib/puppet/pops/loader/module_loaders.rb', line 69

def self.module_loader_from(parent_loader, loaders, module_name, module_path)
  ModuleLoaders::FileBased.new(parent_loader,
                                                     loaders,
                                                     module_name,
                                                     module_path,
                                                     module_name
                                                     )
end

.pcore_resource_type_loader_from(parent_loader, loaders, environment_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.


78
79
80
81
82
83
84
85
# File 'lib/puppet/pops/loader/module_loaders.rb', line 78

def self.pcore_resource_type_loader_from(parent_loader, loaders, environment_path)
  ModuleLoaders::FileBased.new(parent_loader,
    loaders,
    nil,
    environment_path,
    'pcore_resource_types'
  )
end

.system_loader_from(parent_loader, loaders) ⇒ 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.


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/puppet/pops/loader/module_loaders.rb', line 40

def self.system_loader_from(parent_loader, loaders)
  # Puppet system may be installed in a fixed location via RPM, installed as a Gem, via source etc.
  # The only way to find this across the different ways puppet can be installed is
  # to search up the path from this source file's __FILE__ location until it finds the base of
  # puppet.
  #
  puppet_lib = File.realpath(File.join(File.dirname(__FILE__), '../../..'))
  LibRootedFileBased.new(parent_loader,
                                                     loaders,
                                                     nil,
                                                     puppet_lib,   # may or may not have a 'lib' above 'puppet'
                                                     'puppet_system',
                                                      [:func_4x, :func_3x, :datatype]   # only load ruby functions and types from "puppet"
                                                     )
end