Class: Puppet::Pops::Loaders

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/loaders.rb

Defined Under Namespace

Classes: LoaderError, LoaderModuleData, ModuleResolver

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Loaders

Returns a new instance of Loaders.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/pops/loaders.rb', line 10

def initialize(environment)
  # The static loader can only be changed after a reboot
  @@static_loader ||= Loader::StaticLoader.new()

  # Create the set of loaders
  # 1. Puppet, loads from the "running" puppet - i.e. bundled functions, types, extension points and extensions
  #    These cannot be cached since a  loaded instance will be bound to its closure scope which holds on to
  #    a compiler and all loaded types. Subsequent request would find remains of the environment that loaded
  #    the content. PUP-4461.
  #
  @puppet_system_loader = create_puppet_system_loader()

  # 2. Environment loader - i.e. what is bound across the environment, may change for each setup
  #    TODO: loaders need to work when also running in an agent doing catalog application. There is no
  #    concept of environment the same way as when running as a master (except when doing apply).
  #    The creation mechanisms should probably differ between the two.
  #
  @private_environment_loader = create_environment_loader(environment)

  # 3. module loaders are set up from the create_environment_loader, they register themselves
end

Instance Attribute Details

#private_environment_loaderObject (readonly)



8
9
10
# File 'lib/puppet/pops/loaders.rb', line 8

def private_environment_loader
  @private_environment_loader
end

#public_environment_loaderObject (readonly)



7
8
9
# File 'lib/puppet/pops/loaders.rb', line 7

def public_environment_loader
  @public_environment_loader
end

#puppet_system_loaderObject (readonly)



6
7
8
# File 'lib/puppet/pops/loaders.rb', line 6

def puppet_system_loader
  @puppet_system_loader
end

#static_loaderObject (readonly)



5
6
7
# File 'lib/puppet/pops/loaders.rb', line 5

def static_loader
  @static_loader
end

Class Method Details

.clearObject

Clears the cached static and puppet_system loaders (to enable testing)



34
35
36
37
# File 'lib/puppet/pops/loaders.rb', line 34

def self.clear
  @@static_loader = nil
  @puppet_system_loader = nil
end

.find_loader(module_name) ⇒ Loader::Loader

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 the ‘Loaders` instance by looking up the :loaders in the global Puppet context and then uses it to find the appropriate loader for the given `module_name`, or for the environment in case `module_name` is `nil` or empty.

Parameters:

  • module_name (String, nil)

    the name of the module

Returns:

Raises:



47
48
49
50
51
# File 'lib/puppet/pops/loaders.rb', line 47

def self.find_loader(module_name)
  loaders = Puppet.lookup(:loaders) { nil }
  raise Puppet::ParseError, "Internal Error: Puppet Context ':loaders' missing" if loaders.nil?
  loaders.find_loader(module_name)
end

Instance Method Details

#find_loader(module_name) ⇒ Loader::Loader

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 the appropriate loader for the given ‘module_name`, or for the environment in case `module_name` is `nil` or empty.

Parameters:

  • module_name (String, nil)

    the name of the module

Returns:

Raises:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/puppet/pops/loaders.rb', line 60

def find_loader(module_name)
  if module_name.nil? || module_name == ''
    # TODO : Later when fdefinition can be private, a decision is needed regarding what that means.
    #        A private environment loader could be used for logic outside of modules, then only that logic
    #        would see the definition.
    #
    # Use the private loader, this definition may see the environment's dependencies (currently, all modules)
    loader = private_environment_loader()
    raise Puppet::ParseError, 'Internal Error: did not find public loader' if loader.nil?
    loader
  else
    # TODO : Later check if definition is private, and then add it to private_loader_for_module
    #
    loader = public_loader_for_module(module_name)
    raise Puppet::ParseError, "Internal Error: did not find public loader for module: '#{module_name}'" if loader.nil?
    loader
  end
end

#private_loader_for_module(module_name) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/puppet/pops/loaders.rb', line 96

def private_loader_for_module(module_name)
  md = @module_resolver[module_name] || (return nil)
  # Since there is interest in the visibility from the perspective of entities contained in the
  # module, it must be resolved (to provide this visibility).
  # See {#configure_loaders_for_modules}
  unless md.resolved?
    @module_resolver.resolve(md)
  end
  md.private_loader
end

#public_loader_for_module(module_name) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/puppet/pops/loaders.rb', line 87

def public_loader_for_module(module_name)
  md = @module_resolver[module_name] || (return nil)
  # Note, this loader is not resolved until there is interest in the visibility of entities from the
  # perspective of something contained in the module. (Many request may pass through a module loader
  # without it loading anything.
  # See {#private_loader_for_module}, and not in {#configure_loaders_for_modules}
  md.public_loader
end