Skip to content

Publish your gems with bundler gem_tasks

Thomas Volkmar Worm edited this page Nov 15, 2013 · 7 revisions

Since version 0.10, Geminabox supports the standard gemcutter push API and with monkey patching bundler, we can use bundlers gem-tasks as we use them with gems published to rubygems.org. If no authentication is needed, remove the lines asking for username and password.

With using the gemcutter push API, our gems do not have any dependencies to geminabox.

Notice: Removing the monkey patch publishes your gems to rubygems.org, same happens, when bundler code changes make the patch a dead end.

require "bundler/gem_tasks"

module Bundler
  class GemHelper
    unless method_defined?(:rubygem_push)
      raise NoMethodError, "Monkey patching Bundler::GemHelper#rubygem_push failed: did the Bundler API change???"
    end

    def rubygem_push(path)
      print "Username: "
      username = STDIN.gets.chomp
      print "Password: "
      password = STDIN.gets.chomp

      gem_server_url = "https://#{username}:#{password}@gems.example.com/"
      sh %{gem push #{path} --host #{gem_server_url}}

      Bundler.ui.confirm "Pushed #{name} #{version} to #{gem_server_url}"
    end
  end
end