Module: CrazyDoll::PluginManager
- Defined in:
- lib/crazy_doll/plugin_manager.rb
Defined Under Namespace
Classes: Config
Class Method Summary collapse
- .find_usable_errors ⇒ Object
- .load_plugin(path, file_name = nil) ⇒ Object
- .load_plugins ⇒ Object
- .path ⇒ Object
- .plugin_failed(name, p, g) ⇒ Object
- .plugins ⇒ Object
- .problem_with_gems?(gems) ⇒ Boolean
- .problem_with_plugins?(plugins) ⇒ Boolean
- .register_plugins(event_manager, config, plugins = :all) ⇒ Object
- .reload_plugins ⇒ Object
- .unload_plugin(name) ⇒ Object
- .unload_plugins ⇒ Object
Class Method Details
.find_usable_errors ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/crazy_doll/plugin_manager.rb', line 77 def find_usable_errors for name, opts in @plugins[:success] config = opts[:class].config _plugins = config.plugins _gems = config.gems p = problem_with_plugins?(_plugins) g = problem_with_gems?(_gems) next if p == false and g == false plugin_failed(name, p, g) end end |
.load_plugin(path, file_name = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/crazy_doll/plugin_manager.rb', line 65 def load_plugin(path, file_name=nil) file_name ||= File.basename(path) name = file_name.gsub(/\.rb$/,'').split('_').map { |x| x.capitalize }.join begin load path klass = eval(name) @plugins[:success][name.to_sym] = { :path => path, :class => klass } rescue => e @plugins[:error][name.to_sym] = { :path => path, :error => e } end end |
.load_plugins ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/crazy_doll/plugin_manager.rb', line 32 def load_plugins for path in @path next unless FileTest.directory?(path) for e in Dir.entries(path) - ['.','..'] entrie = File.join(path, e) if entrie.match(/_plugin(\.rb)?$/) if FileTest.file?(entrie) load_plugin(entrie) elsif FileTest.directory?(entrie) and FileTest.file?(File.join(entrie, 'plugin.rb')) load_plugin(File.join(entrie, 'plugin.rb'), File.basename(entrie)) end end end end end |
.path ⇒ Object
12 13 14 |
# File 'lib/crazy_doll/plugin_manager.rb', line 12 def path @path end |
.plugin_failed(name, p, g) ⇒ Object
110 111 112 |
# File 'lib/crazy_doll/plugin_manager.rb', line 110 def plugin_failed(name, p, g) @plugins[:not_usable][name] = @plugins[:success].delete(name).update({:plugins => p, :gems => g }) end |
.plugins ⇒ Object
16 17 18 |
# File 'lib/crazy_doll/plugin_manager.rb', line 16 def plugins @plugins end |
.problem_with_gems?(gems) ⇒ Boolean
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/crazy_doll/plugin_manager.rb', line 96 def problem_with_gems?(gems) errors = {} for g,opts in gems begin gem g.to_s, opts[:version] || '>= 0' require opts[:lib] || g.to_s rescue Gem::LoadError => e errors[g] = e end end return false if errors.empty? errors end |
.problem_with_plugins?(plugins) ⇒ Boolean
89 90 91 92 93 94 |
# File 'lib/crazy_doll/plugin_manager.rb', line 89 def problem_with_plugins?(plugins) return false # errors = [] # for plugin in plugins # end end |
.register_plugins(event_manager, config, plugins = :all) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/crazy_doll/plugin_manager.rb', line 20 def register_plugins(event_manager, config, plugins=:all) plugins = @plugins[:success].map { |k,v| k.to_sym } if plugins == :all registered = [] for plugin in plugins if @plugins[:success][plugin] @plugins[:success][plugin][:class].new(event_manager, config) registered << plugin end end registered end |
.reload_plugins ⇒ Object
56 57 58 59 |
# File 'lib/crazy_doll/plugin_manager.rb', line 56 def reload_plugins unload_plugins load_plugins end |
.unload_plugin(name) ⇒ Object
61 62 63 |
# File 'lib/crazy_doll/plugin_manager.rb', line 61 def unload_plugin(name) Object.send(:remove_const, name) rescue false end |
.unload_plugins ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/crazy_doll/plugin_manager.rb', line 48 def unload_plugins for plugin,info in @plugins[:success] unload_plugin(plugin) end @plugins = { :success => {}, :error => {} } return true end |