Pluggability module
Extended With |
|
The Pluggability
module
Constants
- FactoryError
An exception class for
Pluggability
specific errors.- VERSION
Library version
Attributes
- pluggable_classes R
- derivatives R
Return the Hash of derivative classes, keyed by various versions of the class name.
Public Class Methods
Add the @derivatives instance variable to including classes.
Return the ancestor of subclass
that has Pluggability
.
Public Instance Methods
Given the class_name
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 class_name
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
Search for the file that corresponds to mod_name
using the plugin prefixes and current Gem load path and return the path to the first candidate that exists.
Build and return the unique part of the given class_name
either by stripping leading namespaces if the name already has the name of the plugin type in it (eg., ‘My::FooService’ for Service, or by appending the plugin type if it doesn’t.
Given a class_name
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.
Returns true
if any of the plugin_exclusions
match the specified +path.
Find and load all derivatives of this class, using plugin_prefixes
if any are defined, or a pattern derived from the plugin_type
if not. Returns an array of all derivative classes. Load failures are logged but otherwise ignored.
Calculates an appropriate filename for the derived class using the name of the base class and tries to load it via load
. If the including class responds to a method named plugin_prefixes
, its return value (either a String, or an array of Strings) is added to the list of prefix directories to try when attempting to load modules. Eg., if class.plugin_prefixes
returns ['foo','bar']
the require line is tried with both 'foo/'
and 'bar/'
prepended to it.
Return all variants of the name of the given subclass
that can be used to load 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"]
Get/set patterns which cause files in a plugin path to not be loaded. Typical use case is to exclude test/spec directories:
MyFactoryType.plugin_exclude( 'spec/**' )
Set the plugin exclusion patterns which cause files in a plugin path to not be loaded.
Return an Array of all the filenames a plugin of the given mod_name
might map to given the current plugin_prefixes.
Get/set the prefixes that will be used when searching for particular plugins for the calling Class.
Set the prefixes that will be used when searching for particular plugins for the calling Class.
Returns the type name used when searching for a derivative.
Search for the module with the specified mod_name
, using any plugin_prefixes
that have been set. Return the path that was required.