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)
if has_lib
application_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, "lib")) || 0
$LOAD_PATH.insert(application_lib_index + 1, lib_path)
end
config = configuration
loaded_plugins << name
silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init
true
end