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 380
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 *after* the application lib, to allow
# application libraries to override plugin libraries.
if has_lib
application_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, "lib")) || 0
$LOAD_PATH.insert(application_lib_index + 1, lib_path)
Dependencies.load_paths << lib_path
Dependencies.load_once_paths << lib_path
end
# Allow plugins to reference the current configuration object
config = configuration
# Add to set of loaded plugins before 'name' collapsed in eval.
loaded_plugins << name
# Evaluate init.rb.
silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init
true
end