Difference Between Plugins and Ruby Gems

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 project
    in 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.

What's the difference between gems and plugins?

The basic difference is a gem is something that needs to be installed on the system running your Rails application, whereas a plugin is deployed along with your application. More specifically, plugins live in vendor/plugins whereas gems need to be install using rake gem install gem_name.

As for when to use each, gems tend to be easier to keep up to date, but more specifically, some gems use native C code and are compiled specifically for a given operating system (such as Nokogiri). These need to be installed as gems as they will not work when moved to another system. Whereas some things like acts_as_commentable use straight ruby code and can be moved from system to system.

What is the difference between Ruby Gem and Rails plugin?

Gems:

  • Can handle dependencies
  • Can be installed system-wide
  • Can also be vendored (in vendor/gems)
  • Has a concept of versions, can easily specify which version you want

Plugins:

  • Very easy to publish for authors

Apparently, the only advantage for plugins is a powerful advantage, since plugins are still very common. I tend to agree. Publishing a plugin = creating a github repository. Publishing a gem requires you to create a gemspec, and perhaps even meddle with The Gem Beast (rubyforge), which both are PITAs.

what is the best to use - ruby gems or ruby plugins

I think you should have to go with gems if possible. You will have a rich framework with slim applications. If you use a lot of plugins your application will be too heavy. I'm talking from experience. I have an application with a lot of plugins in it and it is hell slow.



Related Topics



Leave a reply



Submit