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 ⇒ 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 ⇒ PluginManager
Returns a new instance of PluginManager.
4 5 6 7 |
# File 'lib/zmb/plugin.rb', line 4 def initialize @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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zmb/plugin.rb', line 29 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| begin load_plugin_source(file) end end end |
#load_plugin_source(file) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/zmb/plugin.rb', line 19 def load_plugin_source(file) begin definition = instance_eval(File.read(file)) definition.definitition_file = File.(file) @plugins << definition rescue Exception nil end end |
#plugin(name) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/zmb/plugin.rb', line 9 def plugin(name) plugin = @plugins.find{|plugin| plugin.name == name} if plugin then plugin.object else nil end end |
#refresh_plugin_sources ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/zmb/plugin.rb', line 44 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
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/zmb/plugin.rb', line 53 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 |