Usually we make gems with Bundler like bundle gem
or rails plugin new
. Bundler provides several useful rake tasks, including rake release
to publish it to RubyGems.org.
This is good for Open Source gems, but when you're building a gem for private use only, it would be very bad if you accidentally release it to RubyGems.org: you cannot remove it immediately, instead you can only "yank" it from the index, and you have to ask the admin to remove it completely.
"Yank" only removes it from index, so that others cannot find it anymore, but if any other existing gems depends on it, it can still be installed, which means that the package is still on RubyGems.org and is downloadable. I did once released a private gem to RubyGems.org accidentally, and it took 2 months until it was pulled down since I sent a removal request.
So can we prevent it being published to RubyGems.org? Yes. Starting from Bundler 1.3.0 there is a gem_push
environment variable you can use. Set it to falsy string and the gem won't be published onto RubyGems.org:
# Add this line at the top of Rakefile in your gem
ENV['gem_push'] = 'off' # Never Push to Rubygems
Note: I tried setting it to false
(boolean lexical value) but it didn't work; the error message would be "no implicit conversion of false into String."