Reputation: 59313
I'm developing two Ruby gems simultaneously, one of which depends on the other. Say my gem names are "foo" and "bar". "bar" depends on "foo", so its gemspec includes this:
s.add_runtime_dependency "foo", "~> 0"
# More dependencies...
And my Gemfile:
source "https://rubygems.org"
gemspec
Of course, running bundle install
now will give me an error since "foo" is placed in a local folder.
I don't want to comment out the dependency line, nor do I want to point it to a local folder, because that would be a local change that I would never commit to my Git repo. It would be taking up space under git status
and it would be in the way when I need to make modifications to the file.
I'm hoping there are some tricks I can do with some environment variables that will let Bundler know where "foo" is, and count it as "already installed". Is that possible?
Upvotes: 3
Views: 124
Reputation: 107959
This trick is done using bundler.
Let's say that gem foo depends upon gem bar. Then in foo's Gemfile, use bundler's path option to point to gem bar:
gem "bar", path: "/home/wayne/lab/bar"
then bundle install
After that, commands such as bundle exec rspec
, bundle exec rake features
, etc., will use the gem "bar" out of your local folder.
When done, revert the gem "bar"
line in Gemfile to its normal form.
If you want to keep the Gemfile modification permanently, you have several options. One is to just check it in with the modification. According to the Gemfile source priority, Bundler will first try to load the gem from the local path, then fall back to installing it from the global source.
If the gem is public, your local modification might be confusing to someone who clones your gem. In that case, since a Gemfile is just ruby code, you can use, for example, an environment variable to turn on your location modification:
# When making concurrent modifications to gem "bar",
# use that gem by its local directory.
if ENV['BAR_GEM_PATH']
gem "bar", path: ENV['BAR_GEM_PATH']
end
Upvotes: 2
Reputation: 449
you can't do it in .gemspec, please put it like following code
gem 'gem_name', path: 'full/path/to/your_gem'
in my exp, it's best way to dev two gem at same time, if you upload one gem to rubygems.org, you can use s.add_runtime_dependency "foo", "~> 0"
, but if you wanna change gem "foo" code, and upadate in another proj, you need to run bundle install
again. it's very waste time to do that.
Upvotes: 0