Simplest Possible Plugin Manager For Rails  

By Ryan Tomayko under Ruby, Rails on 27. October 2005

UPDATE: I ended up making some pretty massive changes. You can configure multiple plugin repositories, install, update, remove, and discover plugins. The directions for installation are still valid but you’ll need to run plugin --help to get a feel for the changes in usage.

UPDATE: The plugin manager has been included with Rails 1.0 RC4. Run script/plugin --help from a fresh Rails app for usage information.

Rails 1.0 RC1 shipped with a simple plugin system - drop a directory under vendor/plugins that contains an init.rb file to be executed at configuration time and an optional lib directory to be placed on the path. Do whatever you please from there. It’s a simple hook into the startup cycle and a much needed addition.

About 19 hours ago, David suggested that people link to their plugins from the Rails Wiki as a kind of interim solution to the problem of not having a standard means of packaging and managing these things. They did and with links to their plugins’ subversion repositories.

Here’s a simple (150 line) plugin manager.

Install it like this:

$ cd my-rails-app
$ curl http://lesscode.org/svn/rtomayko/rails/scripts/plugin > script/plugin
$ chmod +x script/plugin

Then see what plugins are available:

$ ./script/plugin
continuous_builder  http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder
asset_timestamping  http://svn.aviditybytes.com/rails/plugins/asset_timestamping
enumerations_mixin  http://svn.protocool.com/rails/plugins/enumerations_mixin/trunk
calculations        http://techno-weenie.net/svn/projects/calculations/

Next, install stuff to your vendor/plugins directory:

$ ./script/plugin continuous_builder asset_timestamping

Here’s how it works:

  1. Scrape the Plugin page for things that look like subversion repositories with plugins. (Yes, I’m using regular expressions. Yes, I understand the issues. No, I don’t care.)

  2. If vendor/plugins is under subversion control, the script will modify the svn:externals property on that directory and perform an update. You can use normal subversion commands to keep the plugins up to date.

  3. Or, if vendor/plugins is not under subversion control, the plugin is pulled via svn export.

If you want to use svn:externals, make sure you have your vendor/plugins directory under subversion’s control before installing any plugins . If your not sure, do something like this:

$ svn info vendor/plugins
foo:    (Not a versioned resource)
$ svn mkdir vendor/plugins
$ svn ci -m "adding teh plugins directory so I can use this r0x3ring plugin manager..."

This probably won’t work on Windows at the moment and assumes you have the command line subversion client utilities available (svn).

It’s useful as is, but please, make it better.

6 Responses to “Simplest Possible Plugin Manager For Rails”

  1. Ryan Tomayko:

    I wanted to mention that you can put plugin anywhere on your PATH (e.g., /usr/local/bin, /home/you/bin, etc.) and it will search up from the current directory (`pwd` not `$0`) for a Rails environment. So you can just run plugin instead of ./script/plugin or whatever.

    comment at 27. October 2005

  2. Jeremy Kemper:

    Nice hack, Ryan!

    comment at 27. October 2005

  3. Ryan Tomayko:

    Thanks Jeremy.

    I fixed some stuff by the way so if anyone ran into problems installing more than one plugin, grab the latest from the same URL.

    comment at 28. October 2005

  4. Roland:


    I tried to use the plugin manager which is now part of the standard Rails package. Unfortunately it does not seem to work:

    $ ./plugin list
    svn: PROPFIND request failed on ‘/svn/rails/plugins’
    svn: PROPFIND of ‘/svn/rails/plugins’: could not connect to server (http://dev.rubyonrails.com)

    Any ideas?

    comment at 30. December 2005

  5. Duane Johnson:

    Looks like some of the svn repositories are down (or moved). In that case, you have to ‘unsource’ them. Here’s what worked for me:

    ruby script/plugin unsource http://svn.protocool.com/rails/plugins/
    ruby script/plugin unsource http://svn.substance-it.co.uk/public/plugins/
    ruby script/plugin unsource http://homepage.ntlworld.com/easley/plugins/
    ruby script/plugin unsource http://elitists.textdriven.com/svn/plugins/

    comment at 11. January 2006

  6. Walker:

    What I want to do on my blog, is every few hours take the oldest post and move it to the
    front of the queue, all automatically. Anyone know if there is a plugin that can do this or
    a simple way to set up another plugin to do this (use my own feed perhaps)?

    comment at 12. December 2006