Class: Puppet::Pops::Binder::BindingsLoader

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

Overview

The ClassLoader provides a Class instance given a class name or a meta-type. If the class is not already loaded, it is loaded using the Puppet Autoloader. This means it can load a class from a gem, or from puppet modules.

Class Method Summary collapse

Class Method Details

.loadable?(basedir, name) ⇒ String?

If loadable name exists relative to a a basedir or not. Returns the loadable path as a side effect.

Returns:

  • (String, nil)

    a loadable path for the given name, or nil



35
36
37
38
39
# File 'lib/puppet/pops/binder/bindings_loader.rb', line 35

def self.loadable?(basedir, name)
  # note, "lib" is added by the autoloader
  #
  paths_for_name(name).find {|p| Puppet::FileSystem.exist?(File.join(basedir, "lib/puppet/bindings", p)+'.rb') }
end

.provide(scope, name) ⇒ Class?

Returns a XXXXX given a fully qualified class name. Lookup of class is never relative to the calling namespace.

Parameters:

  • name (String, Array<String>, Array<Symbol>, Puppet::Pops::Types::PAnyType)

    A fully qualified class name String (e.g. ‘::Foo::Bar’, ‘Foo::Bar’), a PAnyType, or a fully qualified name in Array form where each part is either a String or a Symbol, e.g. ‘%wPuppetlabs SomeExtension`.

Returns:

  • (Class, nil)

    the looked up class or nil if no such class is loaded

Raises:

  • ArgumentError If the given argument has the wrong type



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/pops/binder/bindings_loader.rb', line 19

def self.provide(scope, name)
  case name
  when String
    provide_from_string(scope, name)

  when Array
    provide_from_name_path(scope, name.join('::'), name)

  else
    raise ArgumentError, "Cannot provide a bindings from a '#{name.class.name}'"
  end
end