Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6726 (new enhancement)

Opened 3 years ago

Last modified 2 years ago

[PATCH] Add support for RubyGem-based plugins

Reported by: wbruce Assigned to: David
Priority: normal Milestone: 2.x
Component: Railties Version: edge
Severity: normal Keywords: gems plugins
Cc: ez@engineyard.com, bitsweat

Description

Attached is a patch to add support for RubyGem-based Rails plugins. The changes should be backwards compatible.

Plugins are loaded from plugin_paths first, as they currently are-- then, if there are any plugins listed in config.plugins that have not been loaded, it attempts to load gems by those names. You can also include version requirements similar to what require_gem expects (in fact, that's what's used beneath the covers), such as:

config.plugins = ['foo', 'bar', 'baz', ['spam', '>0.9.0', '<=1.2.3'], 'eggs']

The trick with gem-based plugins is the fact that you might have many gem plugins installed, but might only want to use a small subset for any given application-- hence the use of config.plugins. Obviously using config.plugins is restrictive-- since if you are using "normal" path-based plugins you have to include them in the list for them to be enabled, but it is elective (and I consider the dependency-resolution mechanism that RubyGems offers well worth maintaining a config.plugins list).

As to how it works: Gems are loaded, then their lib/ paths are added to load_paths and load_once_paths as with any plugin (so autoloading works as expected). init.rb is also loaded in the same way as it is with the current path-based plugins (no need to specifically set it to be autorequired by the gem)-- this is so that 'config', etc are available to the plugin.

Some method renaming has been done to differentiate path-based plugins and the newer gem-based variety. Documentation has been updated (though it is likely far from complete), and existing tests have been updated to support the naming changes. Testing of the new functionality is spotty (mock gems?) and could use some help. I'd be happy to continue work on this as best I can.

I'm sure the implementation is a bit naive, and there may be issues I didn't take into account. In the very least, I'm hoping this sparks some discussion/work on how best to accomplish RubyGem based plugins with Rails.

Cheers, Bruce

Attachments

add_elective_gem_plugin_support.diff (9.6 kB) - added by wbruce on 11/29/06 05:52:32.
Patch to add support for gem plugins

Change History

11/29/06 05:52:32 changed by wbruce

  • attachment add_elective_gem_plugin_support.diff added.

Patch to add support for gem plugins

11/30/06 05:51:18 changed by ezmobius

  • cc set to ez@engineyard.com.

I am all for this. It seems like a no brainer to have plugins be gems. Patch works for me at first try. Cool.

11/30/06 15:54:13 changed by obrie

  • keywords changed from gems to gems plugins.

This was on my TODO list, but you beat me to it :) Great work. Can't wait for this to get into core. +1

01/12/07 10:22:56 changed by bitsweat

  • cc changed from ez@engineyard.com to ez@engineyard.com, bitsweat.

Hot sauce. What about also loading the plugin gems which those in config.plugins depend on?