Difference between plugins and Ruby gems? Difference between plugins and Ruby gems? ruby ruby

Difference between plugins and Ruby gems?


Gem

  • Gem is a packaged ruby application using the packaging system defined by RubyGems.
  • Rails itself is a Gem.

    Rails gem is installed in jruby-1.0\lib\ruby\gems\1.8\gems\rails-1.2.3 as:

    DIR bin
    DIR builtin
    68,465 CHANGELOG
    DIR configs
    DIR dispatches
    DIR doc
    DIR environments
    307 fresh_rakefile
    DIR helpers
    DIR html
    DIR lib
    1,072 MIT-LICENSE
    11,969 Rakefile
    8,001 README
    The lib directory contains all the gem source code.

  • We can install,upgrade and query the gem version.If one uses a tool like my GemInstaller, one can easily automate the installation and loading of RubyGems with a single simple config file.

  • Gem installed for Ruby interpreter can be used system-wide by that interpreter.
  • Gem may be published as a plugin.
  • Can also be vendored in vendor/gems.

Plugin

  • Plugin is an extension of Rails Framework.
  • Can not be upgraded by using a command. To upgrade one have to uninstall and then install upgraded version.
  • Has to be hooked into rails application. (has to have init.rb)
  • Have an install.rb file.
  • Plugin cannot be published as a Gem.
  • Can only be used application wide.

Goldspike plugin is installed in vendor\plugins\rails-integration directory of the application as:
7,089 build.xml
1,141 LICENSE.txt
DIR plugins
6,675 pom.xml
1,447 README
DIR samples
plugins/goldspike directory consists of
24 init.rb
25 install.rb
DIR lib
549 Rakefile
536 README
DIR tasks
DIR test
The lib directory contains all the plugin source code.

Gem vs Plugins

  • Rails had a way of loading plugins from the vendor/plugins/ directory. This will most likely deprecate as Rails has added support for bundling gems with the projectin the vendor/gems/ directory.The gem versions of rspec are the ones that are intended for everyday use. One should go with those unless you are supporting a Rails application in the 1.2.x family or earlier.
  • It often becomes quicker to check-in and check-out of a repository using Gems as you are not including the library in your actual application.There are often lesser problems using Plugins related to incompatibility arising concerning software versions among the distributed team.
  • General rule of thumb is to make Rails-specific functionality a plugin while making more general Ruby libraries into gems.


Gems are installed on the system level while plugins are installed on the application level. That means if two or more apps are running on the same server, they can share gems, but each will have its own plugins. For now I'll suggest one to use gems, as they are easier to maintain as applications scale.