https://github.com/ctran/annotate_models
Annotate Rails classes with schema and routes info
https://github.com/ctran/annotate_models
Keywords
activerecord rails ruby
Keywords from Contributors
activejob mvc rubygems rubocop static-code-analysis code-formatter rspec rack crash-reporting ruby-gem
Last synced: about 10 hours ago
JSON representation
Repository metadata
Annotate Rails classes with schema and routes info
- Host: GitHub
- URL: https://github.com/ctran/annotate_models
- Owner: ctran
- License: other
- Created: 2008-02-27T18:04:38.000Z (about 18 years ago)
- Default Branch: develop
- Last Pushed: 2024-08-05T23:45:54.000Z (over 1 year ago)
- Last Synced: 2026-02-23T22:56:37.717Z (7 days ago)
- Topics: activerecord, rails, ruby
- Language: Ruby
- Homepage:
- Size: 1.59 MB
- Stars: 4,484
- Watchers: 37
- Forks: 673
- Open Issues: 144
- Releases: 16
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Authors: AUTHORS.md
README.md
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_bot factories, i.e. the
(spec|test)/factories/<model>_factory.rbfiles routes.rbfile (for Rails projects)
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, PostgisAdapter 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.
Upgrading to 3.X and annotate models not working?
In versions 2.7.X the annotate gem defaulted to annotating models if no arguments were passed in.
The annotate gem by default would not allow for routes and models to be annotated together.
A change was added in #647.
You can read more here.
There are a few ways of fixing this:
- If using CLI explicitly pass in models flag using
--models
OR
a) Running rails g annotate:install will overwrite your defaults with the annotating models option set to 'true'.
b) In lib/tasks/auto_annotate_models.rake add the models key-value option:
Annotate.set_defaults(
...
'models' => 'true',
...
Install
Into Gemfile from rubygems.org:
group :development do
gem 'annotate'
end
Into Gemfile from Github:
group :development do
gem 'annotate', git: 'https://github.com/ctran/annotate_models.git'
end
Into environment gems from rubygems.org:
gem install annotate
Into environment gems from Github checkout:
git clone https://github.com/ctran/annotate_models.git annotate_models
cd annotate_models
rake gem
gem install dist/annotate-*.gem
Usage
(If you used the Gemfile install, prefix the below commands with bundle exec.)
Usage in Rails
To annotate all your models, tests, fixtures, and factories:
cd /path/to/app
annotate
To annotate just your models, tests, and factories:
annotate --models --exclude fixtures
To annotate just your models:
annotate --models
To annotate routes.rb:
annotate --routes
To remove model/test/fixture/factory/serializer annotations:
annotate --delete
To remove routes.rb annotations:
annotate --routes --delete
To automatically annotate every time you run db:migrate,
either run rails g annotate:install
or add Annotate.load_tasks to your Rakefile.
See the configuration in Rails section for more info.
Usage Outside of Rails
Everything above applies, except that --routes is not meaningful,
and you will probably need to explicitly set one or more --require option(s), and/or one or more --model-dir options
to inform annotate about the structure of your project and help it bootstrap and load the relevant code.
Configuration
If you want to always skip annotations on a particular model, add this string
anywhere in the file:
# -*- SkipSchemaAnnotations
Configuration in Rails
To generate a configuration file (in the form of a .rake file), to set
default options:
rails g annotate:install
Edit this file to control things like output format, where annotations are
added (top or bottom of file), and in which artifacts.
The generated rakefile lib/tasks/auto_annotate_models.rake also contains
Annotate.load_tasks. This adds a few rake tasks which duplicate command-line
functionality:
rake annotate_models # Add schema information (as comments) to model and fixture files
rake annotate_routes # Adds the route map to routes.rb
rake remove_annotation # Remove schema information from model and fixture files
By default, once you've generated a configuration file, annotate will be
executed whenever you run rake db:migrate (but only in development mode).
If you want to disable this behavior permanently,
edit the .rake file and change:
'skip_on_db_migrate' => 'false',
To:
'skip_on_db_migrate' => 'true',
If you want to run rake db:migrate as a one-off without running annotate,
you can do so with a simple environment variable, instead of editing the
.rake file:
ANNOTATE_SKIP_ON_DB_MIGRATE=1 rake db:migrate
Options
Usage: annotate [options] [model_file]*
--additional-file-patterns Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)
-d, --delete Remove annotations from all model files or the routes.rb file
-p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)
--position
--pc, --position-in-class [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of the model file
--pf, --position-in-factory [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of any factory files
--px, --position-in-fixture [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of any fixture files
--pt, --position-in-test [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of any test files
--pr, --position-in-routes [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of the routes.rb file
--ps, --position-in-serializer [before|top|after|bottom]
Place the annotations at the top (before) or the bottom (after) of the serializer files
--w, --wrapper STR Wrap annotation with the text passed as parameter.
If --w option is used, the same text will be used as opening and closing
--wo, --wrapper-open STR Annotation wrapper opening.
--wc, --wrapper-close STR Annotation wrapper closing
-r, --routes Annotate routes.rb with the output of 'rake routes'
--models Annotate ActiveRecord models
-a, --active-admin Annotate active_admin models
-v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation
-c, --show-check-constraints List the table's check constraints in the annotation
-k, --show-foreign-keys List the table's foreign key constraints in the annotation
--ck, --complete-foreign-keys
Complete foreign key names 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, separate multiple dirs with commas
--root-dir dir Annotate files stored within root dir projects, separate multiple dirs with commas
--ignore-model-subdirects Ignore subdirectories of the models directory
--sort Sort columns alphabetically, rather than in creation order
--classified-sort Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns
-R, --require path Additional file to require before loading models, may be used multiple times
-e [tests,fixtures,factories,serializers],
--exclude Do not annotate fixtures, test files, factories, and/or serializers
-f [bare|rdoc|yard|markdown], Render Schema Infomation as plain/RDoc/YARD/Markdown
--format
--force Force new annotations even if there are no changes.
--frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files.
--timestamp Include timestamp in (routes) annotation
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
-I, --ignore-columns REGEX don't annotate columns that match a given REGEX (e.g. `annotate -I '^(id|updated_at|created_at)'`)
--ignore-routes REGEX don't annotate routes that match a given REGEX (e.g. `annotate -I '(mobile|resque|pghero)'`)_
--hide-limit-column-types VALUES
don't show limit for given column types, separated by commas (e.g. `integer,boolean,text`)
--hide-default-column-types VALUES
don't show default for given column types, separated by commas (e.g. `json,jsonb,hstore`)
--ignore-unknown-models don't display warnings for bad model files
--with-comment include database comments in model annotations
--with-comment-column include database comments in model annotations, as its own column, after all others
Option: additional_file_patterns
CLI: --additional-file-patterns
Ruby: :additional_file_patterns
Provide additional paths for the gem to annotate. These paths can include
globs. It is recommended to use absolute paths. Here are some examples:
/app/lib/decorates/%MODEL_NAME%/*.rb/app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb/app/lib/forms/%TABLE_NAME%/*.rb
The appropriate model will be inferred using the %*% syntax, annotating any
matching files. It works with existing filename resolutions (options for which
can be found in the resolve_filename method of annotate_models.rb).
When using in a Rails config, you can use the following:
File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/***/**.rb')
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.
Markdown
The format produced is actually MultiMarkdown, making use of the syntax
extension for tables. It's recommended you use kramdown as your parser if
you want to use this format. If you're using yard to generate
documentation, specify a format of markdown with kramdown as the provider by
adding this to your .yardopts file:
--markup markdown
--markup-provider kramdown
Be sure to add this to your Gemfile as well:
gem 'kramdown', groups => [:development], require => false
WARNING
Don't add text after an automatically-created comment block. This tool
will blow away the initial/final comment block in your models if it looks like
it was previously added by this gem.
Be sure to check the changes that this tool makes! If you are using Git, you
may simply check your project's status after running annotate:
$ git status
If you are not using a VCS (like Git, Subversion or similar), please tread
extra carefully, and consider using one.
Links
- Factory Bot: http://github.com/thoughtbot/factory_bot
- Object Daddy: http://github.com/flogic/object_daddy
- Machinist: http://github.com/notahat/machinist
- Fabrication: http://github.com/paulelliott/fabrication
- SpatialAdapter: http://github.com/pdeffendol/spatial_adapter
- PostgisAdapter: http://github.com/nofxx/postgis_adapter
- PostGISAdapter: https://github.com/dazuma/activerecord-postgis-adapter
License
Released under the same license as Ruby. No Support. No Warranty.
Authors
Owner metadata
- Name: Cuong Tran
- Login: ctran
- Email: cuong.tran@gmail.com
- Kind: user
- Description: Currently at @servicenow
- Website: http://twitter.com/ctran
- Location: San Diego, CA
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/491?v=4
- Repositories: 39
- Last ynced at: 2025-12-27T23:51:16.580Z
- Profile URL: https://github.com/ctran
GitHub Events
Total
- Pull request event: 20
- Fork event: 72
- Issues event: 4
- Watch event: 106
- Issue comment event: 41
- Pull request review comment event: 4
- Pull request review event: 13
Last Year
- Pull request event: 12
- Fork event: 20
- Watch event: 51
- Issue comment event: 8
- Pull request review comment event: 4
- Pull request review event: 7
Committers metadata
Last synced: 5 days ago
Total Commits: 806
Total Committers: 236
Avg Commits per committer: 3.415
Development Distribution Score (DDS): 0.922
Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| cuong.tran | c****n@g****m | 63 |
| Jon Frisby | j****y@m****m | 58 |
| Andrew W. Lee | g****t@d****m | 43 |
| Alex Chaffee | a****x@s****m | 42 |
| Shu Fujita | s****a@n****h | 33 |
| Cuong Tran | c****n@p****m | 33 |
| Guillermo Guerrero Ibarra | w****5@g****m | 26 |
| cuong.tran | c****n@s****m | 22 |
| Cuong Tran | c****n@s****m | 21 |
| dependabot[bot] | 4****] | 18 |
| Weston Triemstra | w****n@n****m | 17 |
| Alexander Belozerov | b****a@g****m | 15 |
| Marcos Augusto | x@n****m | 15 |
| Kamil Bielawski | k****i@f****m | 13 |
| Dmitry Lihachev | l****a@o****u | 13 |
| miyucy | m****y@g****m | 12 |
| Henrik N | h****k@n****e | 11 |
| Turadg Aleahmad | t****g@a****t | 11 |
| Jack Danger Canty | g****t@6****m | 8 |
| Robert Wahler | r****t@g****m | 7 |
| Scott Taylor | s****t@r****m | 6 |
| Brent Greeff | b****f@b****l | 6 |
| djsegal | d****l@w****u | 5 |
| Ryan | r****n | 5 |
| Jeremy Mickelson | J****n@g****m | 5 |
| codeape | d****n@c****t | 5 |
| Artūrs Mekšs | a****s@t****m | 5 |
| yhirano55 | y****o@m****m | 4 |
| Olle Jonsson | o****n@g****m | 4 |
| Nathan Brazil | nb@b****m | 4 |
| and 206 more... | ||
Committer domains:
- me.com: 2
- zerosum.org: 1
- rtlong.com: 1
- markbates.com: 1
- mobilecommons.com: 1
- urgetopunt.com: 1
- audioandpixels.com: 1
- langfeld.me: 1
- dio.jp: 1
- datemyschool.com: 1
- terc.edu: 1
- keyme.net: 1
- btcws10.(none): 1
- larkfarm.com: 1
- ipglider.org: 1
- michaels-mac-book.fritz.box: 1
- ragnarson.com: 1
- zozi.com: 1
- t61.(none): 1
- fastpencil.com: 1
- eastmedia.com: 1
- macreery.com: 1
- yandex.ru: 1
- goa.hu: 1
- gravitystorm.co.uk: 1
- modulus.org: 1
- opengroove.org: 1
- mrjoy.com: 1
- drewlee.com: 1
- stinky.com: 1
- nard.tech: 1
- pragmaquest.com: 1
- servicenow.com: 1
- service-now.com: 1
- netsign.com: 1
- nofxx.com: 1
- fastmail.fm: 1
- openteam.ru: 1
- nyh.se: 1
- aleahmad.net: 1
- 6brand.com: 1
- gearheadforhire.com: 1
- railsnewbie.com: 1
- wisc.edu: 1
- codeape.net: 1
- tieto.com: 1
- bitaxis.com: 1
- ceichhor-pc.nbg.webmasters.de: 1
- spy.net: 1
- ianduggan.net: 1
- wilcoxd.com: 1
- infinum.hr: 1
- cyt.ch: 1
- pjkh.com: 1
- xheo.com: 1
- nicoladmin.fr: 1
- iki.fi: 1
- mail.ru: 1
- twobucks.co: 1
- hitabis.de: 1
- hotmail.co.uk: 1
- mgrachev.com: 1
- sandisk.com: 1
- branch14.org: 1
- kampp.me: 1
- dointeractive.ru: 1
- syrec.org: 1
- davidxia.com: 1
- master-developer.com: 1
- thrownproject.org: 1
- bunnymatic.com: 1
- szemafor.com: 1
- procore.com: 1
- bah.com: 1
- foo.lv: 1
- krautcomputing.com: 1
- manuel-hoffmann.info: 1
- ufo10.lalee.net: 1
- thinkpixellab.com: 1
- jmondo.com: 1
- kudashkin.pro: 1
- pobox.com: 1
- deanperry.net: 1
- sagework.com: 1
- rocketbox.in: 1
- noname.(none): 1
- twinenginelabs.com: 1
- nleger.com: 1
- songkick.com: 1
- anchanto.com: 1
- coliloquy.com: 1
- mycase.com: 1
- ivanyvenian.com: 1
- medwiztech.com: 1
- aiming-inc.com: 1
- vdev00.iad.witopia.net: 1
- multikaos.be: 1
- bonanzle.com: 1
- primexinc.com: 1
- ciber.nl: 1
- proc.ru: 1
- oiax.jp: 1
- lazylabs.com: 1
- tjschuck.com: 1
- newleaders.com: 1
- xpt.com: 1
- ambiescent.com: 1
Issue and Pull Request metadata
Last synced: 15 days ago
Total issues: 71
Total pull requests: 129
Average time to close issues: 9 months
Average time to close pull requests: 6 months
Total issue authors: 69
Total pull request authors: 72
Average comments per issue: 2.72
Average comments per pull request: 1.11
Merged pull request: 11
Bot issues: 0
Bot pull requests: 16
Past year issues: 1
Past year pull requests: 12
Past year average time to close issues: N/A
Past year average time to close pull requests: 4 days
Past year issue authors: 1
Past year pull request authors: 8
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.17
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- alexeyr-ci1 (2)
- mhenrixon (2)
- cmer (1)
- SimBed (1)
- Z2Flow (1)
- nerixim (1)
- richardjonathonharris (1)
- YumaInaura (1)
- richardsondx (1)
- ctran (1)
- rafaelsales (1)
- overdrivemachines (1)
- sarahsehr (1)
- choosen (1)
- n-rodriguez (1)
Top Pull Request Authors
- dependabot[bot] (16)
- nard-tech (7)
- olleolleolle (6)
- drwl (5)
- snyk-bot (4)
- dima4p (2)
- lovro-bikic (2)
- ksouthworth (2)
- carldr (2)
- matteolc (2)
- wteuber (2)
- kianmeng (2)
- hayesr (2)
- sethherr (2)
- alexpech12 (2)
Top Issue Labels
- bug (3)
- reviewed (1)
- non-issue (1)
- needs-more-info (1)
- help-wanted (1)
Top Pull Request Labels
- dependencies (16)
- feature (7)
- needs-rebase (6)
- reviewed (6)
- bug (5)
- refactor (2)
Package metadata
- Total packages: 5
-
Total downloads:
- rubygems: 167,423,042 total
- Total docker downloads: 132,618,078
- Total dependent packages: 73 (may contain duplicates)
- Total dependent repositories: 40,893 (may contain duplicates)
- Total versions: 84
- Total maintainers: 1
gem.coop: annotate
Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema.
- Homepage: https://github.com/ctran/annotate_models
- Documentation: http://www.rubydoc.info/gems/annotate/
- Licenses: Ruby
- Latest release: 3.2.0 (published about 4 years ago)
- Last Synced: 2026-02-27T17:31:46.094Z (4 days ago)
- Versions: 29
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 83,705,542 Total
- Docker Downloads: 66,309,039
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.115%
- Downloads: 0.346%
- Maintainers (1)
rubygems.org: annotate
Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema.
- Homepage: https://github.com/ctran/annotate_models
- Documentation: http://www.rubydoc.info/gems/annotate/
- Licenses: Ruby
- Latest release: 3.2.0 (published about 4 years ago)
- Last Synced: 2026-02-27T20:02:08.237Z (4 days ago)
- Versions: 29
- Dependent Packages: 73
- Dependent Repositories: 40,893
- Downloads: 83,709,718 Total
- Docker Downloads: 66,309,039
-
Rankings:
- Dependent repos count: 0.164%
- Stargazers count: 0.311%
- Downloads: 0.358%
- Dependent packages count: 0.404%
- Average: 0.524%
- Docker downloads count: 0.753%
- Forks count: 1.151%
- Maintainers (1)
proxy.golang.org: github.com/ctran/annotate_models
- Homepage:
- Documentation: https://pkg.go.dev/github.com/ctran/annotate_models#section-documentation
- Licenses: other
- Latest release: v3.2.0+incompatible (published about 4 years ago)
- Last Synced: 2026-02-25T22:02:40.489Z (6 days ago)
- Versions: 24
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 6.463%
- Average: 6.681%
- Dependent repos count: 6.899%
gem.coop: codeape-annotate
Annotates Rails Models, routes, and others
- Homepage: http://github.com/ctran/annotate_models
- Documentation: http://www.rubydoc.info/gems/codeape-annotate/
- Licenses: other
- Latest release: 2.0.0.20090212001 (published over 11 years ago)
- Last Synced: 2026-02-25T22:02:39.081Z (6 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 3,891 Total
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 26.196%
- Downloads: 78.587%
rubygems.org: codeape-annotate
Annotates Rails Models, routes, and others
- Homepage: http://github.com/ctran/annotate_models
- Documentation: http://www.rubydoc.info/gems/codeape-annotate/
- Licenses: other
- Latest release: 2.0.0.20090212001 (published over 11 years ago)
- Last Synced: 2026-02-25T22:02:39.179Z (6 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 3,891 Total
-
Rankings:
- Stargazers count: 0.265%
- Forks count: 0.853%
- Dependent packages count: 15.706%
- Average: 28.439%
- Dependent repos count: 46.782%
- Downloads: 78.591%
Dependencies
- annotate >= 0 development
- byebug >= 0 development
- capybara >= 2.15 development
- listen >= 3.0.5, < 3.2 development
- selenium-webdriver >= 0 development
- web-console >= 3.3.0 development
- webdrivers >= 0 development
- bootsnap >= 1.4.2
- jbuilder ~> 2.7
- puma ~> 5.6.1
- rails ~> 6.0.2, >= 6.0.2.1
- sqlite3 ~> 1.4
- tzinfo-data >= 0
- activerecord >= 3.2, < 8.0
- rake >= 10.4, < 14.0
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
- release-drafter/release-drafter v5 composite
- actions/checkout v1 composite
- ruby/setup-ruby v1 composite
- actions/checkout v3 composite
- github/codeql-action/analyze v2 composite
- github/codeql-action/autobuild v2 composite
- github/codeql-action/init v2 composite
Score: 33.42328093120003