This repository has been archived by the owner on Apr 14, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started implementing the plugin loader
- Loading branch information
Adrien Thebo
committed
Nov 1, 2011
1 parent
24bcba9
commit 114b300
Showing
3 changed files
with
53 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
require 'thread' | ||
|
||
module Wrack | ||
class PluginLoader | ||
|
||
def initialize | ||
@plugin_files = Hash.new(Array.new) | ||
@sem = Mutex.new | ||
end | ||
|
||
def addplugin(plugin_file) | ||
@plugin_files[plugin_file] = [] unless @plugin_files[plugin_file] | ||
end | ||
|
||
def load_file!(file) | ||
@sem.synchronize do | ||
begin | ||
$stderr.puts "Loading file #{file}" | ||
preload_plugins = Wrack::Plugin.registered | ||
Kernel.load file | ||
postload_plugins = Wrack::Plugin.registered | ||
|
||
# Associate which plugins were loaded from the files | ||
@plugin_files[file] = (postload_plugins - preload_plugins) | ||
puts @plugin_files | ||
rescue => e | ||
$stderr.puts "Error while loading plugin file #{plugin_file}: #{e}" | ||
end | ||
end | ||
end | ||
|
||
def unload_file!(file) | ||
constants = @plugin_files[file] | ||
|
||
constants.each do |const| | ||
Object.send(:remove_const, const.name.intern) | ||
end | ||
end | ||
|
||
def reload_known_plugins! | ||
@plugin_files.keys.each do |plugin| | ||
unload_file! plugin | ||
load_file! plugin | ||
end | ||
end | ||
end | ||
end |