概要
現状のスキーマの注釈をコメントとしてファイルの上部や下部に追記してくれる。
- ActiveRecord models
- Fixture files
- Tests and Specs
- Object Daddy exemplars
- Machinist blueprints
- Fabrication fabricators
- Thoughtbot's factory_girl factories, i.e. the (spec|test)/factories/_factory.rb files
- routes.rb file (for Rails projects)
追加される注釈はこんな感じ:
# == 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
. . .
インストール
Gemfile x rubygems.org で:
gem 'annotate', ">=2.6.0"
Gemfile x Github:
gem 'annotate', github: 'ctran/annotate_models'
environment gems に rubygems.org:
gem install annotate
environment gems に Github checkout:
git clone git://github.com/ctran/annotate_models.git annotate_models
cd annotate_models
rake build
gem install pkg/annotate-*.gem
使い方
(もし Gemfile でインストールしてたら後述のコマンドの頭に bundle exec
を足すこと.)
使い方(rails)
注釈を加える: すべての models, tests, fixtures, factories について:
cd /path/to/app
annotate
注釈を加える: models, tests, factories だけ:
annotate --exclude fixtures
注釈を加える: models だけ:
annotate --exclude tests,fixtures,factories
注釈を加える: routes.rbについて:
annotate --routes
注釈を削除する: model/test/fixture/factory
annotate --delete
注釈を削除する: routes.rb
annotate --routes --delete
オプション
Usage: annotate [options] [model_file]*
オプション | 説明 |
---|---|
-d, --delete | 注釈を削除する。 |
-p, --position [before or after] | 注釈を追記する箇所を指定する。 |
--pc, --position-in-class [before or after] | modelファイルにて、注釈を追記する箇所を指定する。 |
--pf, --position-in-factory [before or after] | factoryファイルにて、注釈を追記する箇所を指定する。 |
--px, --position-in-fixture [before or after] | fixtureファイルにて、注釈を追記する箇所を指定する。 |
--pt, --position-in-test [before or after] | testファイルにて、注釈を追記する箇所を指定する。 |
--pr, --position-in-routes [before or after] | routes.rbにて、注釈を追記する箇所を指定する。 |
-r, --routes | 'rake routes'の結果をroutes.rbに追記する。 |
-v, --version | annotateのバージョンを表示する。 |
-m, --show-migration | 注釈にマイグレーションの番号を含める。 |
--model-dir dir | dirにあるmodelファイルに注釈を追加する。 |
--ignore-model-subdirects | modelの副階層を無視する。 |
--sort | カラムをアルファベット順に並べる |
-e [tests,fixtures,factories] | []で囲まれた対象には注記を追記しないようにする。 fixtures, test files, and/or factories --exclude |
-f [bare or rdoc or markdown] | スキーマ情報を描画するフォーマットを指定する。 |
--force | 変更がなくても注記を更新する。 |
--trace | 注記追記に失敗したときスタックトレースを表示する。 |
--timestamp | routes.rbに更新日時を追記する。 |
WARNING
ファイル末尾に追記された注記よりしたにコメントを書かないこと。