module Puppet::Util::InstanceLoader

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

Public Instance Methods

instance_docs(type) click to toggle source

Collect the docs for all of our instances.

# File lib/puppet/util/instance_loader.rb, line 36
def instance_docs(type)
  docs = ""

  # Load all instances.
  instance_loader(type).loadall

  # Use this method so they all get loaded
  loaded_instances(type).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
    mod = self.loaded_instance(name)
    docs += "#{name}\n#{"-" * name.to_s.length}\n"

    docs += Puppet::Util::Docs.scrub(mod.doc) + "\n\n"
  end

  docs
end
instance_hash(type) click to toggle source

Return the instance hash for our type.

# File lib/puppet/util/instance_loader.rb, line 54
def instance_hash(type)
  @instances[type.intern]
end
instance_load(type, path, options = {}) click to toggle source

Define a new type of autoloading.

# File lib/puppet/util/instance_loader.rb, line 15
def instance_load(type, path, options = {})
  @autoloaders ||= {}
  @instances ||= {}
  type = type.intern
  @instances[type] = {}
  @autoloaders[type] = Puppet::Util::Autoload.new(self, path, options)

  # Now define our new simple methods
  unless respond_to?(type)
    meta_def(type) do |name|
      loaded_instance(type, name)
    end
  end
end
instance_loader(type) click to toggle source

Return the Autoload object for a given type.

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

Are we instance-loading this type?

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

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

# File lib/puppet/util/instance_loader.rb, line 64
def loaded_instance(type, name)
  name = name.intern
  return nil unless instances = instance_hash(type)
  unless instances.include? name
    if instance_loader(type).load(name)
      unless instances.include? name
        Puppet.warning(
          "Loaded #{type} file for #{name} but #{type} was not defined"
        )
        return nil
      end
    else
      return nil
    end
  end
  instances[name]
end
loaded_instances(type) click to toggle source

Return a list of the names of all instances

# File lib/puppet/util/instance_loader.rb, line 31
def loaded_instances(type)
  @instances[type].keys
end