| Class | AutomateIt::Plugin::Manager |
| In: |
lib/automateit/plugin/manager.rb
|
| Parent: | Base |
A manager provides high-level wrappers for features, e.g. installing software packages. It does not actually implement these features, but instead manages a set of drivers. When one of the manager‘s wrapper methods is called, it queries the drivers to find the most suitable one and dispatches the user‘s request to that driver.
For example, the PlatformManager is a Manager class that manages a set of Driver instances, including PlatformManager::Uname and PlatformManager::LSB. When you invoke the high-level PlatformManager#query wrapper method, it interrogates the drivers to find which one is best-suited for this method and then dispatches the request to that driver‘s low-level implementation of this method.
The manager subclasses typically have no functionality of their own and just contain wrapper methods and documentation.
| drivers | [RW] | Drivers for this manager as a hash of driver tokens to driver instances. |
Declare that this manager class is abstract. It can be subclassed but will not be instantiated by the Interpreter.
Is a driver available for this method and args? Uses automatic-detection routines and returns a boolean to indicate if a suitable driver is available. Unlike driver_for, this will not raise an exception.
Dispatch a method by guessing its name. This is the recommended way to write wrappers for a Manager methods.
Example:
class MyManager < Plugin::Manager
# Your RDoc here
def my_method(*args)
# Will guess that you want to +dispatch_to+ the +my_method+ by
# introspecting the name of the wrapper method.
dispatch(*args)
end
...
end
Same as dispatch_to but returns nil if couldn‘t dispatch, rather than raising an exception.
Dispatch the method with args and block to the appropriate driver. If the arguments include an option of the form :with => :mytoken argument, then the method will be dispatched to the driver represented by :mytoken. If no :with argument is specified, the most-suitable driver will be automatically selected. If no suitable driver is available, a NotImplementedError will be raised.
Examples:
# Run 'hostnames' method on most appropriate AddressManager driver: address_manager.dispatch_to(:hostnames) # Run AddressManager::Portable#hostnames address_manager.dispatch_to(:hostnames, :with => :portable)
You will typically not want to use this method directly and instead write wrappers that call dispatch because it can guess the name of the method argument for you.
Get the most suitable driver for this method and args. Uses automatic-detection routines and returns the most suitable driver instance found, else raises a NotImplementedError if no suitable driver is found.
Returns structure which helps choose a suitable driver for the method and args. Result is a hash of driver tokens and their suitability levels.
For example, if we ask the AddressManager for suitability levels for the AddressManager#hostnames method, we might find that there are two drivers (:portable is the token for AddressManager::Portable) and that the :linux driver is most appropriate because it has the highest suitability level:
address_manager.driver_suitability_levels_for(:hostnames)
# => {:portable=>1, :linux=>2}
Instantiate drivers for this manager. This method is smart enough that it can be called multiple times and will only instantiate drivers it hasn‘t instantiated yet. All drivers will share an instance of the Interpreter, thus providing common state storage.