to_hashメソッドを追加するだけのGem作成


### 制作物

* [ar_to_hash | RubyGems.org | your community gem host](https://rubygems.org/gems/ar_to_hash)
* [shu0115/ar_to_hash](https://github.com/shu0115/ar_to_hash)

### 参考

* [【gemの作り方】 Rubyのオブジェクトをグンマー県が制圧するgem書いた - is Neet](http://soplana.hateblo.jp/entry/2012/06/01/234259)
* [soplana/to_gunma](https://github.com/soplana/to_gunma)
* [ruby on rails 3 - How Do I Add Methods To ActiveRecord::Base? - Stack Overflow](http://stackoverflow.com/questions/13264337/how-do-i-add-methods-to-activerecordbase)

----

## 環境

```
ruby -v
----------
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin12.0]
----------
```

## 雛形生成

```
cd ~/WORK_DIR
bundle gem ar_to_hash
----------
      create  ar_to_hash/Gemfile
      create  ar_to_hash/Rakefile
      create  ar_to_hash/LICENSE.txt
      create  ar_to_hash/README.md
      create  ar_to_hash/.gitignore
      create  ar_to_hash/ar_to_hash.gemspec
      create  ar_to_hash/lib/ar_to_hash.rb
      create  ar_to_hash/lib/ar_to_hash/version.rb
Initializing git repo in /Users/shu/labo/ar_to_hash
----------
```

```
cd ar_to_hash
```

## Gitリポジトリ作成／ファーストコミット

```
git add . && git commit -m "First commit"
```

### GitHubリポジトリ作成

[https://github.com/repositories/new](https://github.com/repositories/new)

```
Project Name
[ ar_to_hash ]

 => Create repository
```

## GitHubリポジトリへプッシュ

```
git remote add origin git@github.com:shu0115/ar_to_hash.git
git push -u origin master
```

### GitHubリポジトリ

* [shu0115/ar\_to\_hash](https://github.com/shu0115/ar_to_hash)

### .gemspecの編集

```
s ar_to_hash.gemspec
```

```ruby
  spec.summary       = "Add to_hash method."
  spec.description   = "Add to_hash method to ActiveRecord::Base."
  spec.homepage      = "https://github.com/shu0115/ar_to_hash"
```

```
git add . && git commit -m "Update gemspec"
git push origin master
```

---

## Gem実装

lib/ar\_to\_hash.rb

```rb
require "ar_to_hash/version"
require "ar_to_hash/extensions.rb"

module ArToHash
  # Your code goes here...
end
```

/lib/ar\_to\_hash/extensions.rb

```rb
module ActiveRecord
  class Base
    def to_hash
      ActiveSupport::JSON.decode(self.to_json)
    end
  end
end
```

---

### コミット／プッシュ

```
git add . && git commit -m "Update"
git push origin master
```

### ローカルインストール

```
rake install
----------
minimum-omniauth-scaffold 0.0.1 built to pkg/minimum-omniauth-scaffold-0.0.1.gem.
minimum-omniauth-scaffold (0.0.1) installed.
----------
```

or

Gemfile

```
gem 'ar_to_hash', path: "~/WORK_DIR/ar_to_hash"
```

```
bundle install
```

----

## リリース

lib/ar\_to\_hash/version.rb

```rb
module ArToHash
  VERSION = "0.0.1"
end
```

```
git add -A && git commit -m "Release 0.0.1"
git push origin master
```

```
rake release
----------
ar_to_hash 0.0.1 built to pkg/ar_to_hash-0.0.1.gem.
Tagged v0.0.1.
Pushed git commits and tags.
Pushed ar_to_hash 0.0.1 to rubygems.org.
----------
```

### RubyGemsページ

* [ar_to_hash | RubyGems.org | your community gem host](https://rubygems.org/gems/ar_to_hash)

### インストール確認

```
gem uninstall ar_to_hash
----------
Successfully uninstalled ar_to_hash-0.0.1
----------
```

```
gem install ar_to_hash
----------
Fetching: ar_to_hash-0.0.1.gem (100%)
Successfully installed ar_to_hash-0.0.1
1 gem installed
----------
```

## README編集

```md
# ArToHash

TODO: Write a gem description
```

```md
## Usage

TODO: Write usage instructions here
```