load_plugin(directory)
protected
Load the plugin at path unless already loaded.
Each plugin is initialized:
- add its lib directory, if present, to the beginning of the load
path
- evaluate init.rb if present
Returns true if the plugin is successfully loaded or
false if it is already loaded (similar to Kernel#require). Raises
LoadError if the plugin is not found.
Show source
def load_plugin(directory)
name = File.basename(directory)
return false if loaded_plugins.include?(name)
raise LoadError, "No such plugin: #{directory}" unless plugin_path?(directory)
lib_path = File.join(directory, 'lib')
init_path = File.join(directory, 'init.rb')
has_lib = File.directory?(lib_path)
has_init = File.file?(init_path)
$LOAD_PATH.unshift(lib_path) if has_lib
config = configuration
silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init
loaded_plugins << name
true
end