Written by: steve ross on February 11th 2007

After working with Rails for a bit, we form working habits and one of mine is to install the same plugins for each project. You might do the same. I call these my "base plugins." Here's a Rake task that can make this process easier.


rake plugins:install_base

Code (goes in lib/tasks/base_plugins.rake or right in your Rakefile)

require 'yaml'
namespace :plugins do
  desc "install a known list of plugins, specified in config/base_plugins.yml"
  task 'install_base' do
    f = YAML::load_file(File.join(RAILS_ROOT, 'config', 'base_plugins.yml'))
    f.each_pair do |plugin, options|
      force, svn = '', ''
      force = ' --force' if (options[:force] && options[:force].downcase == 'yes')
      svn   = ' -X' if (options[:svn] && options[:svn].downcase == 'yes')
      if force.empty? && File.exist?(File.join(RAILS_ROOT, "vendor/plugins/#{plugin}"))
        puts "Skipping #{plugin} -- already installed and force options not specified."
        cmd = "ruby #{RAILS_ROOT}/script/plugin install #{svn}#{options['repos']} #{plugin}#{force}"
        puts "*** installing #{cmd}"

To use this, just place a file called base_plugins.yml in your config directory and format it as follows:

plugin_name: repos: svn://whatever/place/it/points force: yes svn: no nextpluginname: repos: http://another/place/you/like

The only required entry is "repos", but you can add force: yes to cause the plugin to be installed no matter what. If you want to use svn externals, then use svn: yes, which flips the -X switch on script/plugin install.

Bug noted: There seems to be a spurious ping to the script/plugin that makes it spit out an "already installed" message. This doesn't affect the functionality, however.


POSTSCRIPT: Since this post was written, much water has passed under the bridge. Bundler and Rails templates render this kind of thing somewhat academic.