ぼろぼろ平原

困った

RubyGemsとGitHubに公開したgemの名前を変更する

前提

  • gemをGitHubRubyGemsに公開したけど、あとから名前を変えたくなった
  • oldnameという名前のgemをnewnameという名前にしたい

oldname gem側の作業

以下のコードをoldname gemのどこかに書いて、deprecatedになることを伝える。

warn "[DEPRECATION] This gem has been renamed to `newname` and will no longer be supported. Please switch to `newname` as soon as possible."

さらに以下のコードをoldname.gemspecに追加すると、oldname gemのアップデート時にこのメッセージが出る。

spec.post_install_message = <<-MESSAGE
 ! The 'oldname' gem has been deprecated and has been replaced by 'newname'.
 ! See: https://rubygems.org/gems/newname
 ! And: https://github.com/YourID/newname
MESSAGE

最後にバージョンを1つ上げる。

lib/oldname/version.rb

module OldName
  VERSION = "0.1.1" # テキトーに0.0.1上げる
end

newname gem側の作業

newname.gemspecdescriptionsummaryに以下の文を追加しておくと親切。

Formerly known as 'oldname'.