Method: Puppet::Pops::Loaders#initialize

Defined in:
lib/puppet/pops/loaders.rb

#initialize(environment, for_agent, load_from_pcore = true) ⇒ Loaders

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 a new instance of Loaders.

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puppet/pops/loaders.rb', line 36

def initialize(environment, for_agent, load_from_pcore = true)
  # Protect against environment havoc
  raise ArgumentError.new(_("Attempt to redefine already initialized loaders for environment")) unless environment.loaders.nil?
  environment.loaders = self
  @environment = environment
  @loaders_by_name = {}

  add_loader_by_name(self.class.static_loader)

  # 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. Cache loader(optional) - i.e. what puppet stores on disk via pluginsync; gate behind the for_agent flag.
  # 3. 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 =
    if for_agent
      @puppet_cache_loader = create_puppet_cache_loader
      create_environment_loader(environment, @puppet_cache_loader, load_from_pcore)
    else
      create_environment_loader(environment, @puppet_system_loader, load_from_pcore)
    end

  Pcore.init_env(@private_environment_loader)

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