Module PluginFactory
In: lib/pluginfactory.rb

A mixin that adds PluginFactory class methods to a base class, so that subclasses may be instantiated by name.

Methods

Attributes

logger_callback  [RW] 

Public Class methods

Raise an exception if the object being extended is anything but a class.

Inclusion callback — extends the including class.

If the logger callback is set, use it to pass on a log entry. First argument is

Public Instance methods

Given the className of the class to instantiate, and other arguments bound for the constructor of the new object, this method loads the derivative class if it is not loaded already (raising a LoadError if an appropriately-named file cannot be found), and instantiates it with the given args. The className may be the the fully qualified name of the class, the class object itself, or the unique part of the class name. The following examples would all try to load and instantiate a class called "FooListener" if Listener included Factory

  obj = Listener::create( 'FooListener' )
  obj = Listener::create( FooListener )
  obj = Listener::create( 'Foo' )

Returns an Array of registered derivatives

Return the Hash of derivative classes, keyed by various versions of the class name.

Returns the type name used when searching for a derivative.

Build and return the unique part of the given className either by stripping leading namespaces if the name already has the name of the factory type in it (eg., ‘My::FooService’ for Service, or by appending the factory type if it doesn’t.

Given a className like that of the first argument to create, attempt to load the corresponding class if it is not already loaded and return the class object.

Inheritance callback — Register subclasses in the derivatives hash so that ::create knows about them.

Calculates an appropriate filename for the derived class using the name of the base class and tries to load it via require. If the including class responds to a method named derivativeDirs, its return value (either a String, or an array of Strings) is added to the list of prefix directories to try when attempting to require a modules. Eg., if class.derivativeDirs returns [‘foo’,’bar’] the require line is tried with both ‘foo/’ and ‘bar/’ prepended to it.

Make a list of permutations of the given modname for the given subdir. Called on a DataDriver class with the arguments ‘Socket’ and ‘drivers’, returns:

  ["drivers/socketdatadriver", "drivers/socketDataDriver",
   "drivers/SocketDataDriver", "drivers/socket", "drivers/Socket"]

If the factory responds to the derivativeDirs method, call it and use the returned array as a list of directories to search for the module with the specified modName.

[Validate]