on Rails : Annotated Models

http://rails.office.drecom.jp/takiuchi/archive/90で知り,http://rss.yawpsoft.com/Riding_Rails/2006/03/03/Annotated_modelsで理解を深める.

Annotated Modelsって?

達人プログラマのDave Thomasさんが考えたRailsプラグイン.モデルのファイルの一番上に,現在のそのモデルのスキーマ定義がコメントとして追加される.ちょっとした,それでいて有用性のあるプラグインですね.

インストール

$ script/plugin install http://svn.pragprog.com/Public/plugins/annotate_models
$ rake annotate_models

でよい.ためしに「はじめようRuby on Rails」で作成した「みんスケ」でやってみよう.

$ ./script/plugin install http://svn.pragprog.com/Public/plugins/annotate_models
+ ./annotate_models/ChangeLog
+ ./annotate_models/README
+ ./annotate_models/lib/annotate_models.rb
+ ./annotate_models/tasks/annotate_models_tasks.rake
$ rake annotate_models
(in /pass/to/scheduler)
Annotating Group
Annotating Schedule
Annotating User

それじゃぁ実際に付加されているか見てみよう.

# == Schema Information
# Schema version: 6
#
# Table name: schedules
#
#  id        :integer(11)   not null, primary key
#  datetime  :datetime      
#  title     :string(255)   
#  content   :text          
#  file_name :string(255)   
#  user_id   :integer(11)   
#

class Schedule < ActiveRecord::Base
  belongs_to :user
  …

例とはちょっと形式が違うかな.何はともあれちゃんと動いて良かった.はじめ,上の瀧内さんのトコに書いてある方法で入らなかったので焦ってたよ.