Dan
Dan

Reputation: 1697

How do I freeze a specific gem into a Rails 3 application?

My question is very similar to How do I freeze gems into a Rails 3 application?, but I only want to freeze a single modified gem. The answers to that question seem to result in bundling all the application's gems.

In case it's relevant, I need to do this so the modified gem gets installed on Heroku.

I checked the bundle-install doc but it didn't seem to address this situation. I can't imagine it's that uncommon, though. Any guidance is appreciated.

Upvotes: 1

Views: 851

Answers (3)

Dan
Dan

Reputation: 1697

With thanks to those who answered the question with related approaches, I ended up going with the approach mentioned in this sister question. For the sake of clarity, this is what I did:

  1. Repackage modified gem as its own gem. This takes a little finagling but is described well in the RubyGems Guides. Move said gem into your source directory (I used vendor/gems)

  2. In the project's Gemfile, point to the location of the new gem:

    gem "modified_gem", :path => "vendor/gems/modified_gem"

  3. Add new gem to version control, make sure bundle install isn't messed up with funky settings (e.g. --local), and cross your fingers.

Someone also mentioned that it's possible to mix in changes to the gem instead of overriding source files. I don't know anything more about this technique except that it should be possible.

Upvotes: 2

tadman
tadman

Reputation: 211610

If you're using bundler, which is the default for Rails 3, you can always fork the gem to your own git repository and add that definition to your Gemfile with whatever location it can be found at:

gem 'thegem', :git => 'git://github.com/cloned_to_me/thegem.git'

Another option is to use bundle package to save copies of the gems in vendor/cache. These can then be later installed using bundle install --local according to the documentation.

This is the closest thing to the Rails 2 "freeze" method, but has the added advantage of saving the gems before they are installed, not after, avoiding any platform-specific problems as was the case previously.

Upvotes: 3

jefflunt
jefflunt

Reputation: 33954

Well, Bundler is going to freeze all of them, and the idea is that you want to freeze not only a single gem, but the collection of gems that produced a working copy of your app.

That being said, on your local dev machine, you can do bundle update [name of gem] and it will update just that one gem to the latest version within the restrictions specified in your Gemfile, which also updates your Gemfile.lock, which effectively updates just that one gem on Heroku when you next deploy.

Upvotes: 3

Related Questions