概要
- gem
annotate
の導入 annotate
自動化のためのファイル生成
annotateとは
annotate
を導入するとモデルの情報を
各モデルのファイルの先頭、
もしくは末尾にコメントをつけてくれるgemです。
annotateを使うメリット
今まではモデルの情報を確認する時にschema.rb
ファイルを確認していたがschema
、routing
などのファイルを
直接ファイルを開くことなく
確認できるようになります。
実装内容
開発環境に
.
gem annotate
のイントール
.
$ be rails g annotate:instal
.
annotate
自動化のためのファイルを
上記コマンドで生成できます。
.
実行結果がこちらです。
.
rails g annotate:install
Running via Spring preloader in process 88928
create lib/tasks/auto_annotate_models.rake
.
lib/tasks配下に生成されています。
.
$ be annotate
.
上記コマンドでモデルの情報を
各モデルのファイルの先頭、
もしくは末尾に反映してくれます。
.
# == Schema Information
#
# Table name: articles
#
# id :bigint not null, primary key
# content :string
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_articles_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
.
こんな感じで反映されていたら導入完了です。
コメント