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 38 def instance_hash(type) 39 @instances[type.intern] 40 end
instance_load(type, path)
click to toggle source
Define a new type of autoloading.
# File lib/puppet/util/instance_loader.rb 16 def instance_load(type, path) 17 @autoloaders ||= {} 18 @instances ||= {} 19 type = type.intern 20 @instances[type] = {} 21 @autoloaders[type] = Puppet::Util::Autoload.new(self, path) 22 @instance_loader_lock = Puppet::Concurrent::Lock.new 23 24 # Now define our new simple methods 25 unless respond_to?(type) 26 meta_def(type) do |name| 27 loaded_instance(type, name) 28 end 29 end 30 end
instance_loader(type)
click to toggle source
Return the Autoload
object for a given type.
# File lib/puppet/util/instance_loader.rb 43 def instance_loader(type) 44 @autoloaders[type.intern] 45 end
instance_loading?(type)
click to toggle source
Are we instance-loading this type?
# File lib/puppet/util/instance_loader.rb 11 def instance_loading?(type) 12 defined?(@autoloaders) and @autoloaders.include?(type.intern) 13 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 48 def loaded_instance(type, name) 49 @instance_loader_lock.synchronize do 50 name = name.intern 51 instances = instance_hash(type) 52 return nil unless instances 53 unless instances.include? name 54 if instance_loader(type).load(name, Puppet.lookup(:current_environment)) 55 unless instances.include? name 56 Puppet.warning(_("Loaded %{type} file for %{name} but %{type} was not defined") % { type: type, name: name }) 57 return nil 58 end 59 else 60 return nil 61 end 62 end 63 instances[name] 64 end 65 end
loaded_instances(type)
click to toggle source
Return a list of the names of all instances
# File lib/puppet/util/instance_loader.rb 33 def loaded_instances(type) 34 @instances[type].keys 35 end