15.7. Summary

Rails uses the plugin architecture to allow all kinds of functionality to be added to a Rails project without making the core even bigger than it already is. The script/plugin script covers the discovery, installation, and removal of plugins.

Creating your own plugin is a great way to package common code for use across multiple projects. The basic skeleton is created by a Rails generator, including hooks for behavior on installation, load, and plugin removal.

Your plugin can create its own generators, which allows your own arbitrary templates to be called from the script/generator method. With some judicious environment tweaking, a generator test helper used in the Rails core can be adapted to test your generators. Generator behavior is guided by a manifest file, which accepts several commands that involve the creation of directories and files.

The plugin structure discussed in the previous chapter can be augmented with actual behavior in the modules, and again, tested despite being outside the environment of the Rails application.

After the plugin is developed, it can easily be hosted on one of several freely available servers and distributed to the Rails community at large.

Get Professional Ruby on Rails™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.