せかいや

いまいるここを、おもしろく http://sekai-in-the-box.appspot.com/

【Ruby】パーフェクトRuby 学習感想文 ~第13章

それでは13章を読んでいきます。

(参考・経緯など)
パーフェクトRuby 学習感想文 ~はじめに

 

P438 誤植だと思う

誤: 全章までで
正: 前章までで


  

P439 事前にGitがインストール済み?

 

Bundlerでの雛形作成は・・・Gitがインストール済みである必要があります。

 
入れてるよー。なのにエラーがでる↓

C:\>bundle gem gem_sample_pruby -b -t
Unfortunately, a fatal error has occurred. Please see the Bundler
troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/cli.rb:689:in ``': Permission denied - git config user.name (Errno::EACCES)
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/cli.rb:689:in `gem'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `run'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in `dispatch'
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in `start'

あ、ひょっとしてGitシェル上で動かすの??

■Git Bush上

$ ruby -v
ruby 2.0.0p247 (2013-06-27) [i386-mingw32]

動いてる!Gitシェル上でRubyが動いてる。

改めてシェル上で実行してうまくいきました。

$ bundle gem gem_sample_pruby -b -t
      create  gem_sample_pruby/Gemfile
      create  gem_sample_pruby/Rakefile
      create  gem_sample_pruby/LICENSE.txt
      create  gem_sample_pruby/README.md


 

P447 Rakeビルドエラー

$ rake build
rake aborted!
cannot load such file -- rspec/core/rake_task
c:/repositories/gem_sample_pruby/Rakefile:2:in `<top (required)>'
(See full trace by running task with --trace)

rspecをインストールし解決

gem install rspec


 

rake release コマンドでエラー

$ rake release
gem_sample_pruby 0.0.1 built to pkg/gem_sample_pruby-0.0.1.gem.
rake aborted!
There are files that need to be committed first.

Tasks: TOP => release
(See full trace by running task with --trace)

コミットしてからじゃないとだめみたい。
GitHubにリモートリポジトリを作成してcommit/pushを行う。

$ git push https://github.com/sekaiya/gem_sample_pruby.git master


再チャレンジ。
またもエラー。

$ rake release
gem_sample_pruby 0.0.1 built to pkg/gem_sample_pruby-0.0.1.gem.
Tagged v0.0.1.
Untagging v0.0.1 due to error.
rake aborted!
Couldn't git push. `git push  2>&1' failed with the following output:

fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

ローカルブランチをリモートに追跡させる

$ git push --set-upstream origin master


再チャレンジ。
またもエラー

rake aborted!
Your rubygems.org credentials aren't set. Run `gem push` to set them.

 
credentialsファイルを、リポジトリディレクトリ内に作っていたのが敗因。
「~」ディレクトリ内に作成しないといけない。

 ~/.gem/credentials

再チャレンジ

$ rake release
gem_sample_pruby 0.0.1 built to pkg/gem_sample_pruby-0.0.1.gem.
Tag v0.0.1 has already been created.
Pushed gem_sample_pruby 0.0.1 to rubygems.org.

公開できたみたい。
公開できたというのは、どこで分かるのかな。

https://rubygems.org/gems/gem_sample_pruby

おおー。私がいる。

 
って待って?gem名はユニークなの?
となると、このパーフェクトRubyのサンプルを自分で実装した馬鹿正直は私だけ?

他に同じ馬鹿正直タイプがいると、本の通りに作ったら公開時にエラーになるの?
やってみよう。


 

すでに公開されているgem名でgemを作成する

どうなるのかな。
"world" gemを作ってみよう。
すでに公開されている ⇒https://rubygems.org/gems/world

$ rake release
world 0.0.1 built to pkg/world-0.0.1.gem.
Tagged v0.0.1.
Username for 'https://github.com': sekaiya
Password for 'https://sekaiya@github.com':
Username for 'https://github.com': sekaiya
Password for 'https://sekaiya@github.com':
Pushed git commits and tags.
rake aborted!
Pushing gem to https://rubygems.org...
Repushing of gem versions is not allowed.
Please use `gem yank` to remove bad gem releases.

Tasks: TOP => release
(See full trace by running task with --trace)

エラーになった。
公開されているものよりもバージョンが低いから?


師匠(Rubyの分かる先輩)に聞いてみるも、
「gemの重複登録はできないよ」
とのこと。

やっぱりかー。
ってことはこの本のサンプルを作る人は必ずエラーに。。。
先着1名様に限りエラーなし!みたいな企画だったのかな。