Ruby gem equivalent of "pip install -e"?

Let's assume you have your gem code residing in a folder (say my_project/mygem/lib). You have some Ruby code in my_project that you want using the mygem code.

What I'd do is add mygem/lib to the $LOAD_PATH global variable in the beginning of said files. Kinda like this:

$LOAD_PATH << File.expand_path('lib', './mygem') # Resolve global paths

require 'a_file' # Would require "mygem/lib/a_file.rb"

I am not sure if this is exactly what you want to achieve, but from the description I infer that you want to have a local copy of some gem and reference that gem in your project. If this is the case, you can (usually) achieve it in two steps:

  1. Clone the gem from VCS (in most cases: git), e.g. git clone url-of-the-gem-repo
  2. Reference the local copy using Bundler :path, e.g. gem "some-gem", :path => "/path/to/local/copy"

If the gem is stored at github, an even better way is to first fork it at github and then clone your own copy. Then, if you provide any improvements to the code in the local repo, you can easily share it with the world using a pull request.


There are two common approaches one might use with bundler:

  1. one executes bundle install --path vendor/bundle and does not run bundle update unless everything is tested.
  2. one tells a bundler to use a local version of the gem:
    • in Gemfile (this is not supported in mymaingem.gemspec due to rubygems maintainence issues): gem 'mycutegem', :git => 'git://github.com/myname/mycutegem', :branch => 'master';
    • in command line: bundle config local.mycutegem /path_to_local_git/mycutegem.

The first approach will download everything into subfolder of your current project (here it’d be vendor/bundle.) Feel free to modify everything there, it’ll be reflected.

The second approach is likely better. You are to clone the gem from github and instruct bundle to use your local clone of the respective git repository. This approach provides you with an ability to publish the changes to your main gem into the repository. As soon as dependent repo is published as well, the up-to-date version will be retrieven by your gem subscribers, assuming they have not instructed their bundlers to use their locals.

Hope this helps.

Tags:

Ruby

Gem