Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between plugins and Ruby gems?

What is the difference between plugins and gems? What are the different uses of each? Where and why would you use one over the other?

like image 255
Mr. Black Avatar asked Apr 02 '11 04:04

Mr. Black


People also ask

Why should I use Ruby gem?

Ruby Gems software permits you to download, install, and employ Ruby software packages on your scheme easily. Here, the software package is known as 'gem' which comprises a packaged Ruby application or library. Some of the gems deliver command-line efficacies to aid automate errands and speed-up the work.

What are Ruby on Rails gems?

Gems in Rails are libraries that allow any Ruby on Rails developer to add functionalities without writing code. You can also call Ruby on Rails gems as plugins for adding features. A Ruby gem enables adding features without creating the code again and again.

How do gems work in Ruby?

Gems can be used to extend or modify functionality in Ruby applications. Commonly they're used to distribute reusable functionality that is shared with other Rubyists for use in their applications and libraries. Some gems provide command line utilities to help automate tasks and speed up your work.


2 Answers

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.
like image 114
Piyush Mattoo Avatar answered Oct 14 '22 12:10

Piyush Mattoo


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.

like image 26
serengeti12 Avatar answered Oct 14 '22 11:10

serengeti12