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
-
Fabrication fabricators
-
Thoughtbot's factory_girl factories, i.e. the (spec|test)/factories/<model>_factory.rb files
-
routes.rb file
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¶ ↑
Into Gemfile from rubygems.org:
gem 'annotate', ">=2.5.0.pre1"
Into Gemfile from Github:
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
Into environment gems From rubygems.org:
gem install annotate
Into environment gems from Github checkout:
git clone git://github.com/ctran/annotate_models.git annotate_models cd annotate_models rake build gem install pkg/annotate-*.gem
USAGE¶ ↑
(If you used the Gemfile install, prefix the below commands with `bundle exec`.)
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 remove annotations:
annotate -d
To automatically annotate after running 'rake db:migrate', ensure you've added annotate_models to your Rails project's Gemfile, and run this:
rails g annotate_models:install
This will produce a .rake file that will ensure annotation happens after migration (but only in development mode), and provide configuration options you can use to tailor the output.
If you want to always skip annotations on a particular model, add this string anywhere in the file:
# -*- SkipSchemaAnnotations
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 --ignore-model-subdirects Ignore subdirectories of the models directory --sort Sort columns alphabetically, rather than in creation order -R, --require path Additional files to require before loading models -e, --exclude [tests,fixtures] Do not annotate fixtures, test files, or both -f [bare|rdoc|markdown], Render Schema Infomation as plain/RDoc/Markdown --format --force Force new annotations even if there are no changes. --trace If unable to annotate a file, print the full stack trace, not just the exception message.
SORTING¶ ↑
By default, columns will be sorted in database order (i.e. the order in which migrations were run).
If you prefer to sort alphabetically so that the results of annotation are consistent regardless of what order migrations are executed in, use –sort.
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 MODELS BEFORE USING THIS TOOL!
LINKS¶ ↑
-
Factory Girl: github.com/thoughtbot/factory_girl
-
Object Daddy: github.com/flogic/object_daddy
-
Machinist: github.com/notahat/machinist
-
Fabrication: github.com/paulelliott/fabrication
-
SpatialAdapter: github.com/pdeffendol/spatial_adapter
-
PostgisAdapter: github.com/nofxx/postgis_adapter
LICENSE:¶ ↑
Released under the same license as Ruby. No Support. No Warranty.
AUTHORS:¶ ↑
-
Original code by: Dave Thomas – Pragmatic Programmers, LLC <agilewebdevelopment.com/plugins/annotate_models>
-
Overhauled by: Alex Chaffee <alexch.github.com> alex@stinky.com
-
Gemmed by: Cuong Tran <github.com/ctran> ctran@pragmaquest.com
-
Maintained by: Alex Chaffee and Cuong Tran
-
Homepage: github.com/ctran/annotate_models
With help from:
-
Jack Danger - github.com/JackDanger
-
Michael Bumann - github.com/bumi
-
Henrik Nyh - github.com/henrik
-
Marcos Piccinini - github.com/nofxx
-
Neal Clark - github.com/nclark
-
Jacqui Maher - github.com/jacqui
-
Nick Plante - github.com/zapnap - blog.zerosum.org
-
Pedro Visintin - github.com/peterpunk - www.pedrovisintin.com
-
Bob Potter - github.com/bpot
-
Gavin Montague - github.com/govan
-
Alexander Semyonov - github.com/rotuka
-
Nathan Brazil - github.com/bitaxis
-
Ian Duggan github.com/ijcd
-
Jon Frisby github.com/mrjoy
-
Tsutomu Kuroda
-
Kevin Moore
-
Philip Hallstrom
-
Brent Greeff
-
Paul Alexander
-
Dmitry Lihachev
-
qichunren
and many others that I may have missed to add.