Gems On Rails

Get Version 0.7.2

→ ‘gemsonrails’

aka ‘vendor everything’

What

Link or freeze RubyGems into your rails apps, instead of just plugins. This allows you to ‘vendor everything’ – pushing all dependent gems into your rails app thus ensuring your application will be guaranteed to work when deployed. Your application is no longer dependent on the gems that are/aren’t available on your target deployment environment.

Installation and The Basics

First you install the gem:

$ sudo gem install gemsonrails

Then you deploy the gem into your target Rails application:

$ cd rails_app_folder
$ gemsonrails

This installs some rake tasks into your app to help you freeze or link gems:

$ rake -T | grep "gems:" 
rake gems:freeze    # Freeze a RubyGem into this Rails application; init.rb will be loaded on startup.
rake gems:link      # Link a RubyGem into this Rails application; init.rb will be loaded on startup.
rake gems:unfreeze  # Unfreeze/unlink a RubyGem from this Rails application

Finally, for each gem your application uses you can either freeze a version into the app (only for gems that do not require native compilation), or link a gem with your app (useful for gems that require native compilation)

$ rake gems:freeze GEM=map_by_method
Unpacked map_by_method 0.6.0 to 'map_by_method-0.6.0'

$ ls vendor/gems/map_by_method-0.6.0/
CHANGELOG       README          Rakefile        init.rb         lib             test

$ cat vendor/gems/map_by_method-0.6.0/init.rb 
require File.join(File.dirname(__FILE__), 'lib', 'map_by_method')

Restricting which environments a gem is loaded into

You can restrict which RAILS_ENVs the gem will be loaded for, using ONLY; e.g.

$ rake gems:freeze GEM=<gemname> ONLY=development
$ rake gems:link GEM=<gemname> ONLY=production,staging

In the former, only in development mode will the gem be loaded. In the latter, only in production or staging mode will the gem be loaded from the deployment gem server

Upgrading from old GemsOnRails versions

All the freezing and linking functionality is in the plugin installed by the gemsonrails command. To upgrade, simple install the new gem version, and re-run the gemsonrails command. You application will now have the newest rake tasks and functionality.

Forum

http://groups.google.com/group/gemsonrails

How to submit patches

Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.

Licence

This code is free to use under the terms of the MIT licence.

Contact

Comments are welcome. Send an email to Dr Nic Williams.

Dr Nic, 1st June 2007
Theme extended from Paul Battley