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.
# File railties/lib/initializer.rb, line 292
def load_plugin(directory)
name = File.basename(directory)
return false if loaded_plugins.include?(name)
# Catch nonexistent and empty plugins.
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)
# Add lib to load path.
$LOAD_PATH.unshift(lib_path) if has_lib
# Allow plugins to reference the current configuration object
config = configuration
# Evaluate init.rb.
silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init
# Add to set of loaded plugins.
loaded_plugins << name
true
end