Hi All,
Here's what I'm planning on working on tonight - if anyone else thinks
this is worth doing, I could definitely use some help...
("You're doing it all wrong" is perfectly valid help, as long as you
tell me how to do it right!)
In the spirit of the rake 'freeze_rails' and 'unfreeze_rails' tasks, I
will be working on implementing freeze_gem/unfreeze_gem.
== Why? ==
You want to use a gem in your rails application but you don't have
full 'gem install' access to either your local machine or your
eventual deployment machine.
== What? ==
freeze_gem will unpack the specified gem into
RAILS_ROOT/vendor/frozen_gems (unfreeze_gem removes it).
== How? ==
So far, what I've sketched out is:
Given usage: `freeze_gem GEMNAME` in RAILS_ROOT
1. Check to see if GEMNAME is installed locally
2. If yes, go to 3, else `gem install GEMNAME --install-dir=/tmp`, set
GEM_HOME to /tmp
3. `mkdir vendor/frozen_gems` if necessary, `cd vendor/frozen_gems`
4. `gem unpack GEMNAME`
== Loading Frozen Gems ==
Running freeze_gem also installs the 'frozen_gem_loader' plugin if
necessary. The frozen_gem_loader plugin is something like:
frozen_gem_loader/init.rb
unless Object.const_defined?(:Gem)
require 'rubygems'
end
Dir.glob("#{RAILS_ROOT}/vendor/frozen_gems/*") do |directory|
next if File.basename(directory)[0] == ?. || !File.directory?(directory)
if File.directory?("#{directory}/lib")
$LOAD_PATH.unshift "#{directory}/lib"
end
$LOAD_PATH.uniq!
end
== Some Complications ==
- Gem versions: there should really only be one version of any
particular gem frozen at any one time.
- Platform issues: it really only makes sense to freeze pure ruby
gems. Is it possible to determine if a gem is pure ruby or not?
- Dependencies: things get a lot more complicated if multiple
dependencies have to be installed and frozen.
--ryan
--
Ryan Raaum
http://www.rockefeller.edu -- Bacterial Pathogenesis and Immunology
http://www.worldmartial.com -- Black Belt Instructor
http://locomotive.sourceforge.net -- Self contained one-click Rails for Mac OS X