Class: Fhlow::PluginPool
- Inherits:
-
Object
- Object
- Fhlow::PluginPool
- Defined in:
- lib/module_fhlow/pluginpool.rb
Overview
A Pluginpool is a container that loads, initializes and stores references to the loaded plugins.
Class Method Summary collapse
Instance Method Summary collapse
-
#each(&_block) ⇒ Object
Calls &block for each Plugin.
-
#initialize(_plugindir, _actualLeaf, _pen, _log) ⇒ PluginPool
constructor
Loads and initializes the loaded plugins.
-
#printMe ⇒ Object
Prints all loaded plugins.
Constructor Details
#initialize(_plugindir, _actualLeaf, _pen, _log) ⇒ PluginPool
Loads and initializes the loaded plugins.
_plugindir
-
The direcotry where the plugins can be found.
_actualLeaf
-
Reference to the Leaf you are working on.
_pen
-
Reference to a Pen output object.
_log
-
Reference to a Log object.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/module_fhlow/pluginpool.rb', line 37 def initialize(_plugindir, _actualLeaf, _pen, _log) @pool = Array.new @log = _log @pen = _pen @plugindir = _plugindir @actualLeaf = _actualLeaf Dir.glob(@plugindir + "*.rb").each do |plugin| pluginname = File.basename(plugin, ".rb").capitalize require plugin @pool.push(Kernel.const_get(pluginname).new(@actualLeaf, @pen, @log)) @log.info(self.class, "loaded plugin "+plugin) end end |
Class Method Details
.each_configfile(_plugindir, &_block) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/module_fhlow/pluginpool.rb', line 77 def PluginPool.each_configfile(_plugindir, &_block) Dir.glob(_plugindir+"*.rb").each do |plugin| pluginname = File.basename(plugin, ".rb").capitalize if File.exist?(_plugindir+pluginname+".flw") _block.call(_plugindir+pluginname+".flw") else raise Fhlow::FhlowException.new(pluginname), "Does not provide its default configuration file: "+ @plugindir + pluginname +".flw" end end end |
Instance Method Details
#each(&_block) ⇒ Object
Calls &block for each Plugin. This is a Wraper to Array.each.
- &_block
-
The Block that will be invoked for each Plugin.
73 74 75 |
# File 'lib/module_fhlow/pluginpool.rb', line 73 def each(&_block) @pool.each(&_block) end |
#printMe ⇒ Object
Prints all loaded plugins.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/module_fhlow/pluginpool.rb', line 57 def printMe width = 50 @pen.print ",", "-"*width, "+\n" @pen.print "|", " Pluginpool:".ljust(width),"|\n" @pen.print "+", "-"*width, "+\n" @pool.each do |plugin| str = " ["+@pen.lightgreen+plugin.to_s+@pen.clear+"]"+@pen.clear @pen.print "|", str.ljust(width+(str.length-@pen.uncolored(str).length)), "|\n" end @pen.print "`", "-"*width, "+\n" end |