annotate:モデルやFixtureにスキーマ(テーブル)情報を表示[RubyGem]


RubyGemの「Annotate」はモデルなどに対してスキーマ情報を記述してくれるGemです。対応しているファイルの種別は次のとおりです。

  • モデル
  • Fixtureファイル(FactoryGirl含む)
  • Specファイル
  • routes.rb
# == 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に以下を追加してbundle installを実行。

gem 'annotate'

Railsのプロジェクトに導入する場合は、ターミナルで次のコマンドを実行します。

rails g annotate:install

すると次のrakeタスクを実行できます。

rake annotate_models
rake annotate_routes
rake remove_annotation

😸 annotateの追加コマンド

bundle exec annotate

🐠 annotateをスキップしたい場合のコメント

# -*- SkipSchemaAnnotations

🖥 VULTRおすすめ

VULTR」はVPSサーバのサービスです。日本にリージョンがあり、最安は512MBで2.5ドル/月($0.004/時間)で借りることができます。4GBメモリでも月20ドルです。 最近はVULTRのヘビーユーザーになので、「ここ」から会員登録してもらえるとサービス開発が捗ります!

📚 おすすめの書籍