LoginSignup
2
1

More than 3 years have passed since last update.

gem作ってみた

Posted at

準備

# gem自信のupdate
gem update --system

# bundlerのupdate
gem update bundler

# generatorからプロジェクト作成
bundle gem new_gem -t

-tはテストも作成するoption
defaultでRSpec

他のgemと名前がかぶってはいけないので

gem search new_gem

で名前がかぶっていないことを確認しましょう。

雛形を作成することができたらnew_gem.gemspecを編集します

spec.summary       = %q{TODO: Write a short summary, because Rubygems requires one.}
spec.description   = %q{TODO: Write a longer description or delete this line.}
spec.homepage      = "TODO: Put your gem's website or public repo URL here."

TODOと書かれている箇所を編集していきます

summary -> サマリー
description -> 長めのサマリー
homepage -> https://github.com/takakuda/new_gem

といった感じです

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
と書かれている箇所は社内用のgemを外部に公開しないために公開して良いホストを指定する箇所です。
RubyGems.orgに公開するのでごっそりこのあたりの記述は消します。

作成したgemをlocalで確認

new_gemを作った同じ階層にテスト用のフォルダを作成し

bundle init

Gemfileを作成します

new_gem
├── Gemfile
├── README.md
├── Rakefile
├── bin
│   ├── console
│   └── setup
├── lib
│   ├── new_gem
│   │   └── version.rb
│   └── new_gem.rb
├── miura.gemspec
└── spec
    ├── new_gem_spec.rb
    └── spec_helper.rb
new_gem_test
├── Gemfile
├── Gemfile.lock

Gemfileでは

gem "new_gem", path: "../new_gem"

でlocalのgemをinstallします

その後にbundleを実行

あとはtest用のfileを作成してgemをrequireで呼べば確認できます

確認後公開用にリポジトリを作成し、https://rubygems.org/でアカウントを作成して有効な状態にすればリリースの準備は完了です

リリース

リリースはgemspecのあるディレクトリでrake releaseを実行

自分のプロファイルページに追加されていれば完了です!
https://rubygems.org/profiles/takakuda

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1