I need to freeze two gems and make my project refer to those gems from its project folder.
I know many ways to do it in Rails, but how do I do it manually in Ruby?
开发者_运维知识库I am using jeweler based on advice from my previous question "Starting a Ruby project: github + build tool".
You could use them independently of the rubygems infrastructure by first unpacking each gem into vendor/gems (or whatever path within your project):
cd yourapp
mkdir -p vendor/gems
cd vendor/gems
gem unpack gem1
gem unpack gem2
[etc.]
... and then adding all the frozen gems' lib directories into your load path:
$:.unshift(*Dir[File.dirname(__FILE__) + "/vendor/gems/**/lib"])
What about using Bundler? You could simply lock your application gems with it.
My first suggestion would also be to use Bundler and lock your bundle. You can even put the bundle inside your application directory if you want to distribute the gems with it, though this might lead to problems if a gem contains an extension with native code and you're distributing it to a different platform.
By the way, Rails 3 uses Bundler for gem management exclusively. There will be no rake rails:freeze:gems
in Rails 3 anymore.
As another option, if you don't want to use Bundler for some reason, you could manually put the lib dir of a gem to some subdirectory of the lib dir in your app, add it to your load path and require it manually. If a gem contains pure Ruby code without any extension this might do well but it would be hard to maintain since you'd need to do updates manually.
精彩评论