module Puppet::Util::InstanceLoader

A module that can easily autoload things for us. Uses an instance of Puppet::Util::Autoload

Public Instance Methods

instance_hash(type) click to toggle source

Return the instance hash for our type.

   # File lib/puppet/util/instance_loader.rb
39 def instance_hash(type)
40   @instances[type.intern]
41 end
instance_load(type, path) click to toggle source

Define a new type of autoloading.

   # File lib/puppet/util/instance_loader.rb
17 def instance_load(type, path)
18   @autoloaders ||= {}
19   @instances ||= {}
20   type = type.intern
21   @instances[type] = {}
22   @autoloaders[type] = Puppet::Util::Autoload.new(self, path)
23   @instance_loader_lock = Puppet::Concurrent::Lock.new
24 
25   # Now define our new simple methods
26   unless respond_to?(type)
27     meta_def(type) do |name|
28       loaded_instance(type, name)
29     end
30   end
31 end
instance_loader(type) click to toggle source

Return the Autoload object for a given type.

   # File lib/puppet/util/instance_loader.rb
44 def instance_loader(type)
45   @autoloaders[type.intern]
46 end
instance_loading?(type) click to toggle source

Are we instance-loading this type?

   # File lib/puppet/util/instance_loader.rb
12 def instance_loading?(type)
13   defined?(@autoloaders) and @autoloaders.include?(type.intern)
14 end
loaded_instance(type, name) click to toggle source

Retrieve an already-loaded instance, or attempt to load our instance.

   # File lib/puppet/util/instance_loader.rb
49 def loaded_instance(type, name)
50   @instance_loader_lock.synchronize do
51     name = name.intern
52     instances = instance_hash(type)
53     return nil unless instances
54     unless instances.include? name
55       if instance_loader(type).load(name, Puppet.lookup(:current_environment))
56         unless instances.include? name
57           Puppet.warning(_("Loaded %{type} file for %{name} but %{type} was not defined") % { type: type, name: name })
58           return nil
59         end
60       else
61         return nil
62       end
63     end
64     instances[name]
65   end
66 end
loaded_instances(type) click to toggle source

Return a list of the names of all instances

   # File lib/puppet/util/instance_loader.rb
34 def loaded_instances(type)
35   @instances[type].keys
36 end