| Class | HandlerPlugin |
| In: |
lib/webgen/plugin.rb
|
| Parent: | Plugin |
You can use this class for easily handling similiar things, for example, various markup to HTML converters.
To use it, just create a subclass of HandlerPlugin which will be the manager for a class of plugins. This subclass should specify all the methods, specific implementations should provide. The specific implementations should then be derived from this subclass, each using a different name for register_handler. Then you can retrieve a specific implementation by using the method registered_handlers[<NAME>] on the manager class.
Defines the name for the specific handler under which the handler instance can be retrieved.
# File lib/webgen/plugin.rb, line 517
517: def self.register_handler( name )
518: self.config.infos[:handler_for] = name
519: end
Returns the name of the specific handler.
# File lib/webgen/plugin.rb, line 522
522: def self.registered_handler
523: self.config.infos[:handler_for]
524: end
Returns all handler instances as a hash. The names defined with HandlerPlugin#register_handler can be used to retrieve a specific handler instance.
# File lib/webgen/plugin.rb, line 528
528: def registered_handlers
529: if !defined?( @registered_handlers_cache ) || @cached_plugins_hash != @plugin_manager.plugins.keys.hash
530: @registered_handlers_cache = {}
531: @plugin_manager.plugins.each do |name, plugin|
532: if plugin.kind_of?( self.class ) && plugin.class.registered_handler
533: @registered_handlers_cache[plugin.class.registered_handler] = plugin
534: end
535: end
536: @cached_plugins_hash = @plugin_manager.plugins.keys.hash
537: end
538: @registered_handlers_cache
539: end