Skip to content

miyucy/annotate_models

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Annotate (aka AnnotateModels)

Add a comment summarizing the current schema to the top or bottom of each of your…

* ActiveRecord models
* Fixture files
* Tests and Specs
* Object Daddy exemplars
* Machinist blueprints
* Thoughtbot's factory_girl factories, i.e. the (spec|test)/factories/<model>_factory.rb files

The schema comment looks like this:

# == 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
  . . .

It also annotates geometrical columns, geom type and srid, when using SpatialAdapter or PostgisAdapter:

# == Schema Info
#
# Table name: trips
#
#  local           :geometry        point, 4326
#  path            :geometry        line_string, 4326

Also, if you pass the -r option, it’ll annotate routes.rb with the output of “rake routes”.

INSTALL

From rubyforge:

sudo gem install annotate

From github:

git clone git://github.com/ctran/annotate_models.git annotate
cd annotate
gem build annotate.gemspec
sudo gem install annotate-<version>.gem

USAGE

To annotate all your models, tests, fixtures, etc.:

cd /path/to/app
annotate

To annotate your models and tests:

annotate --exclude fixtures

To annotate just your models:

annotate --exclude tests,fixtures

To annotate routes.rb:

annotate -r

To automatically annotate after running ‘rake db:migrate’:

[needs more clarity] unpack the gem into vendor/plugins, or maybe vendor/gems, or maybe just require tasks/migrate.rake.

If you install annotate_models as a plugin, it will automatically adjust your rake db:migrate tasks so that they update the annotations in your model files for you once the migration is completed.

Warning: ImageMagick installs a tool called ‘annotate` too (if you’re using MacPorts it’s in ‘/opt/local/bin/annotate`. So if you see Usage: annotate imagein.jpg imageout.jpg then put `/usr/bin` ahead on the path and you’ll get ours instead.

OPTIONS

Usage: annotate [options] [model_file]*
    -d, --delete                     Remove annotations from all model files
    -p, --position [before|after]    Place the annotations at the top (before) or the bottom (after) of the model file
    -r, --routes                     Annotate routes.rb with the output of 'rake routes'
    -v, --version                    Show the current version of this gem
    -m, --show-migration             Include the migration version number in the annotation
    -i, --show-indexes               List the table's database indexes in the annotation
    -s, --simple-indexes             Concat the column's related indexes in the annotation
        --model-dir dir              Annotate model files stored in dir rather than app/models
    -R, --require path               Additional files to require before loading models
    -e [tests,fixtures,factories]    Do not annotate fixtures, test files, and/or factories
        --exclude

WARNING

Note that this code will blow away the initial/final comment block in your models if it looks like it was previously added by annotate models, so you don’t want to add additional text to an automatically created comment block.

* * Back up your model files before using... * *

LICENSE:

Released under the same license as Ruby. No Support. No Warranty.

AUTHOR:

Original code by: Dave Thomas – Pragmatic Programmers, LLC Overhauled by: Alex Chaffee Gemmed by: Cuong Tran Maintained by: Alex Chaffee and Cuong Tran Homepage: github.com/ctran/annotate_models

Modifications by:

- Alex Chaffee - http://github.com/alexch - alex@pivotallabs.com
- Cuong Tran - http://github.com/ctran - ctran@pragmaquest.com
- Jack Danger - http://github.com/JackDanger
- Michael Bumann - http://github.com/bumi
- Henrik Nyh - http://github.com/henrik
- Marcos Piccinini - http://github.com/nofxx
- Neal Clark - http://github.com/nclark
- Jacqui Maher - http://github.com/jacqui
- Nick Plante - http://github.com/zapnap - http://blog.zerosum.org
- Pedro Visintin - http://github.com/peterpunk - http://www.pedrovisintin.com
- Bob Potter - http://github.com/bpot
- Gavin Montague - http://github.com/govan/
- Alexander Semyonov - http://github.com/rotuka/
- Nathan Brazil - http://github.com/bitaxis/

and many others that I may have missed to add.

About

Annotate ActiveRecord models as a gem

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%