Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

80 | Chapter 3: Rails Plugins


The plugin locator searches for plugins under the configured paths, recursively.
Because a recursive search is performed, you can organize plugins into directories;
for example,vendor/plugins/active_record_acts andvendor/plugins/view_extensions.


The actual plugin locating and loading system is extensible, and you can write your
own strategies. The locator (which by default isRails::Plugin::FileSystemLocator)
searches for plugins; the loader (by default Rails::Plugin::Loader) determines
whether a directory contains a plugin and does the work of loading it.


To write your own locators and loaders, examinerailties/lib/rails/plugin/locator.rb
andrailties/lib/rails/plugin/loader.rb. The locators (more than one locator can be
used) and loader can be changed with configuration directives:


config.plugin_locators += [MyPluginLocator]
config.plugin_loader = MyPluginLoader

Installing Rails Plugins


Plugins are most often installed with the built-in Rails plugin tool,script/plugin.
This plugin tool has several commands:


discover/source/unsource/sources
The plugin tool uses an ad-hoc method of finding plugins. Rather than requiring
you to specify the URL of a plugin repository,script/plugintries to find it for you.
One way it does this is by scraping the “Plugins” page of the Rails wiki*for
source URLs. This can be triggered with thediscover command.
Thesourceandunsourcecommands add and remove source URLs, respectively.
Thesources command lists all current source URLs.


install/update/remove
These commands install, update, and uninstall plugins. They can take an HTTP
URL, a Subversion URL (svn://orsvn+ssh://), or a bare plugin name, in which
case the list of sources is scanned.


script/plugin installtakes an option,-x, that directs it to manage plugins as Sub-
version externals. This has the advantage that the directory is still linked to the exter-
nal repository. However, it is a bit inflexible—you cannot cherry-pick changes from
the upstream repository. We will examine some better options later.


RaPT


RaPT (http://rapt.rubyforge.org/) is a replacement for the standard Rails plugin
installer,script/plugin. It can be installed withgem install rapt.


The first advantage that RaPT has is that it can search for plugins from the command
line. (The second advantage is that it is extremely fast, because it caches everything.)


*http://wiki.rubyonrails.org/rails/pages/Plugins

Free download pdf