LoginSignup
48
44

More than 5 years have passed since last update.

最近使ったお気に入りの Awesome な RubyGems たち

Last updated at Posted at 2013-02-22

最近使って、気に入った RubyGems を紹介します。

  • acts_as_paranoid
  • better_errors / binding_of_caller
  • tapp
  • pry-rails / pry-doc
  • awesome_print
  • terminal-notifier-guard
  • guard-bundler
  • json_expressions

acts_as_paranoid

いわずと知れた、論理削除のための Gem ですが、バージョン 0.4 から rails3_acts_as_paranoid から acts_as_paranoid に名前が変更になりました。

better_errors / binding_of_caller

Rails の実行時の味気ないエラー画面をとっても Awesome にしてくれる!!!

tapp

tapp は Print Debug を手助けしてくれる Gem です。
メソッドチェーンの間に tapp を挟んでおけば、途中の値が Print され、(ほとんどの場合)さらに続きのチェーンが何事もなかったかのように実行されます。

ほとんどの場合と書きましたが、うまくいかない場合のことなど、詳しくはこちらを参考のこと。

pry-rails / pry-doc

いわずと知れた、irb の代替 pry を Rails でデフォルトで読み込んでくれる pry-rails。
pry-doc を入れると、Gem のドキュメントも見ることができます。

awesome_print

irb/pry の結果等をとっても Awesome にしてくれる!!!

どんな結果かはここで見てみてください。
Design Recipe 別館 Blog - irb でのオブジェクトの表示を更に見易く - awesome print

自分は pryrc にこんな風に書いて、awesome_print がある場合には自動的に読み込んでくれるようにしています。

.pryrc
begin
  require "awesome_print"
  AwesomePrint.pry!
rescue LoadError => err
  puts "no awesome_print :("
end

terminal-notifier-guard

Guard の結果を Mountain Lion の通知センターを使って通知する。
今までは Growl を使っていましたが、止めました。

guard-bundler

Guardfile に以下を追加しておけば、Gemfile が更新されたときに勝手に bundle コマンドを実行して、Gem のインストールを行ってくれます。

Guardfile
guard 'bundler' do
  watch('Gemfile')
  # Uncomment next line if Gemfile contain `gemspec' command
  # watch(/^.+\.gemspec/)
end

json_expressions

RSpec や UnitTest で JSON 出力をテストするための Gem。

# This is what we expect the returned JSON to look like
pattern = {
  user: {
    id:         :user_id,                    # "Capture" this value for later
    username:   'chancancode',               # Match this exact string
    full_name:  'Godfrey Chan',
    email:      'godfrey@example.com',
    type:       'Administrator',
    points:     Fixnum,                      # Any integer value
    homepage:   /\Ahttps?\:\/\/.*\z/i,       # Let's get serious
    created_at: wildcard_matcher,            # Don't care as long as it exists
    updated_at: wildcard_matcher,
    posts: [
      {
        id:      Fixnum,
        subject: 'Hello world!',
        user_id: :user_id,                   # Match against the captured value
        tags: [
          'announcement',
          'welcome',
          'introduction'
        ]                                    # Ordering of elements does not matter by default
      }.ignore_extra_keys!,                  # Skip the uninteresting stuff
      {
        id:      Fixnum,
        subject: 'An awesome blog post',
        user_id: :user_id,
        tags:    ['blog' , 'life']
      }.ignore_extra_keys!
    ].ordered!                               # Ensure the posts are in this exact order
  }
}

JSON_RESULT.should match_json_expression(pattern)

単純な値だけではなく、型や並び順、必須なものだけとか、いろいろな条件を指定することができます。

参考にした Rails アプリ

48
44
1

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
48
44