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.
logger_callback | [RW] |
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' )
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"]