便利なコメントを自動生成: annotate_models

annotate_models https://github.com/ctran/annotate_models

Ruby on Rails 4(たしか)から、モデルに属性を書かなくなった。 そのおかげでモデルのファイルを見ても何のプロパティを持っているかわからない。

schema.rbを見ればいいのだが、あれはなかなか巨大だし見るのは辛い。

annotate_modelsを使うとこんな感じでモデルのファイルに自動でコメントを生成してくれる。

# == Schema Info
#
# Table name: line_items
#
#  id                  :integer(11)    not null, primary key
#  quantity            :integer(11)    not null
#  product_id          :integer(11)    not null
#  unit_price          :float
#  order_id            :integer(11)
#

 class LineItem < ActiveRecord::Base
   belongs_to :product
  . . .

かなり気が利くgemでオプションを色々指定できる。

ストファイルにも書いたり、どのタイミングでファイルに書き込むかとかフォーマットとか。