Class: PluginManager
- Inherits:
-
Object
- Object
- PluginManager
- Defined in:
- lib/zmb/plugin.rb
Instance Attribute Summary collapse
-
#plugin_sources ⇒ Object
Returns the value of attribute plugin_sources.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
Instance Method Summary collapse
- #add_plugin_source(directory) ⇒ Object
-
#initialize(delegate = nil) ⇒ PluginManager
constructor
A new instance of PluginManager.
- #load_plugin_source(file) ⇒ Object
- #plugin(name) ⇒ Object
- #refresh_plugin_sources ⇒ Object
- #reload_plugin(name) ⇒ Object
Constructor Details
#initialize(delegate = nil) ⇒ PluginManager
Returns a new instance of PluginManager.
4 5 6 7 8 |
# File 'lib/zmb/plugin.rb', line 4 def initialize(delegate=nil) @delegate = delegate @plugins = Array.new @plugin_sources = Array.new end |
Instance Attribute Details
#plugin_sources ⇒ Object
Returns the value of attribute plugin_sources.
2 3 4 |
# File 'lib/zmb/plugin.rb', line 2 def plugin_sources @plugin_sources end |
#plugins ⇒ Object
Returns the value of attribute plugins.
2 3 4 |
# File 'lib/zmb/plugin.rb', line 2 def plugins @plugins end |
Instance Method Details
#add_plugin_source(directory) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zmb/plugin.rb', line 30 def add_plugin_source(directory) @plugin_sources << directory definition_files = Dir[ File.join(File.(directory), "*.rb"), File.join(File.(directory), "*", "plugin.rb") ] definition_files.map do |file| load_plugin_source(file) end end |
#load_plugin_source(file) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/zmb/plugin.rb', line 20 def load_plugin_source(file) begin definition = instance_eval(File.read(file)) definition.definitition_file = File.(file) @plugins << definition rescue Exception @delegate.debug(self, "Cannot load source `#{file}`", $!) end end |
#plugin(name) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/zmb/plugin.rb', line 10 def plugin(name) plugin = @plugins.find{|plugin| plugin.name == name} if plugin then plugin.object else nil end end |
#refresh_plugin_sources ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/zmb/plugin.rb', line 43 def refresh_plugin_sources sources = @plugin_sources @plugins = Array.new @plugin_sources = Array.new sources.each{|directory| add_plugin_source directory} end |
#reload_plugin(name) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zmb/plugin.rb', line 52 def reload_plugin(name) plugin = @plugins.find{|plugin| plugin.name == name} if plugin then @plugins.delete(plugin) reloaded = load_plugin_source plugin.definitition_file @plugins << plugin if not reloaded reloaded end end |