{"id":13483902,"url":"https://github.com/ctran/annotate_models","last_synced_at":"2025-05-07T11:52:04.554Z","repository":{"id":384237,"uuid":"1462","full_name":"ctran/annotate_models","owner":"ctran","description":"Annotate Rails classes with schema and routes info","archived":false,"fork":false,"pushed_at":"2024-08-05T23:45:54.000Z","size":1670,"stargazers_count":4466,"open_issues_count":143,"forks_count":655,"subscribers_count":42,"default_branch":"develop","last_synced_at":"2025-04-30T07:43:47.465Z","etag":null,"topics":["activerecord","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctran.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2008-02-27T18:04:38.000Z","updated_at":"2025-04-26T15:36:32.000Z","dependencies_parsed_at":"2023-07-05T14:44:38.012Z","dependency_job_id":"91587afa-3cf9-4b94-b101-7569aeba7f9f","html_url":"https://github.com/ctran/annotate_models","commit_stats":{"total_commits":806,"total_committers":241,"mean_commits":"3.3443983402489628","dds":0.9280397022332506,"last_synced_commit":"5d01c4171990c4fe7b9b0977b05ce14a98209e53"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctran%2Fannotate_models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctran%2Fannotate_models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctran%2Fannotate_models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctran%2Fannotate_models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctran","download_url":"https://codeload.github.com/ctran/annotate_models/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251735798,"owners_count":21635393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","rails","ruby"],"created_at":"2024-07-31T17:01:16.668Z","updated_at":"2025-05-07T11:52:04.524Z","avatar_url":"https://github.com/ctran.png","language":"Ruby","readme":"## Annotate (aka AnnotateModels)\n\n[![Gem Version](https://badge.fury.io/rb/annotate.svg)](http://badge.fury.io/rb/annotate)\n[![Downloads count](https://img.shields.io/gem/dt/annotate.svg?style=flat)](https://rubygems.org/gems/annotate)\n[![CI Status](https://github.com/ctran/annotate_models/workflows/CI/badge.svg)](https://github.com/ctran/annotate_models/actions?workflow=CI)\n[![Coveralls](https://coveralls.io/repos/ctran/annotate_models/badge.svg?branch=develop)](https://coveralls.io/r/ctran/annotate_models?branch=develop)\n[![Maintenability](https://codeclimate.com/github/ctran/annotate_models/badges/gpa.svg)](https://codeclimate.com/github/ctran/annotate_models)\n\nAdd a comment summarizing the current schema to the top or bottom of each of your...\n\n- ActiveRecord models\n- Fixture files\n- Tests and Specs\n- Object Daddy exemplars\n- Machinist blueprints\n- Fabrication fabricators\n- Thoughtbot's factory_bot factories, i.e. the `(spec|test)/factories/\u003cmodel\u003e_factory.rb` files\n- `routes.rb` file (for Rails projects)\n\n\nThe schema comment looks like this:\n\n```ruby\n# == Schema Info\n#\n# Table name: line_items\n#\n#  id                  :integer(11)    not null, primary key\n#  quantity            :integer(11)    not null\n#  product_id          :integer(11)    not null\n#  unit_price          :float\n#  order_id            :integer(11)\n#\n\nclass LineItem \u003c ActiveRecord::Base\n  belongs_to :product\n  . . .\n```\n\nIt also annotates geometrical columns, `geom` type and `srid`,\nwhen using `SpatialAdapter`, `PostgisAdapter` or `PostGISAdapter`:\n\n```ruby\n# == Schema Info\n#\n# Table name: trips\n#\n#  local           :geometry        point, 4326\n#  path            :geometry        line_string, 4326\n```\n\nAlso, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake routes`.\n\n\n## Upgrading to 3.X and annotate models not working?\n\nIn versions 2.7.X the annotate gem defaulted to annotating models if no arguments were passed in.\nThe annotate gem by default would not allow for routes and models to be annotated together.\nA [change was added in #647](https://github.com/ctran/annotate_models/pull/647).\nYou [can read more here](https://github.com/ctran/annotate_models/issues/663).\n\nThere are a few ways of fixing this:\n\n- If using CLI explicitly pass in models flag using `--models`\n\nOR\n\na) Running `rails g annotate:install` will overwrite your defaults with the annotating `models` option set to `'true'`.\n\nb) In `lib/tasks/auto_annotate_models.rake` add the `models` key-value option:\n\n```ruby\n    Annotate.set_defaults(\n      ...\n      'models'                      =\u003e 'true',\n      ...\n```\n\n## Install\n\nInto Gemfile from rubygems.org:\n\n```ruby\ngroup :development do\n  gem 'annotate'\nend\n```\n\nInto Gemfile from Github:\n\n```ruby\ngroup :development do\n  gem 'annotate', git: 'https://github.com/ctran/annotate_models.git'\nend\n```\n\nInto environment gems from rubygems.org:\n\n    gem install annotate\n\nInto environment gems from Github checkout:\n\n    git clone https://github.com/ctran/annotate_models.git annotate_models\n    cd annotate_models\n    rake gem\n    gem install dist/annotate-*.gem\n\n## Usage\n\n(If you used the Gemfile install, prefix the below commands with `bundle exec`.)\n\n### Usage in Rails\n\nTo annotate all your models, tests, fixtures, and factories:\n\n    cd /path/to/app\n    annotate\n\nTo annotate just your models, tests, and factories:\n\n    annotate --models --exclude fixtures\n\nTo annotate just your models:\n\n    annotate --models\n\nTo annotate routes.rb:\n\n    annotate --routes\n\nTo remove model/test/fixture/factory/serializer annotations:\n\n    annotate --delete\n\nTo remove routes.rb annotations:\n\n    annotate --routes --delete\n\nTo automatically annotate every time you run `db:migrate`,\neither run `rails g annotate:install`\nor add `Annotate.load_tasks` to your `Rakefile`.\n\nSee the [configuration in Rails](#configuration-in-rails) section for more info.\n\n### Usage Outside of Rails\n\nEverything above applies, except that `--routes` is not meaningful,\nand you will probably need to explicitly set one or more `--require` option(s), and/or one or more `--model-dir` options\nto inform `annotate` about the structure of your project and help it bootstrap and load the relevant code.\n\n## Configuration\n\nIf you want to always skip annotations on a particular model, add this string\nanywhere in the file:\n\n    # -*- SkipSchemaAnnotations\n\n### Configuration in Rails\n\nTo generate a configuration file (in the form of a `.rake` file), to set\ndefault options:\n\n    rails g annotate:install\n\nEdit this file to control things like output format, where annotations are\nadded (top or bottom of file), and in which artifacts.\n\nThe generated rakefile `lib/tasks/auto_annotate_models.rake` also contains\n`Annotate.load_tasks`. This adds a few rake tasks which duplicate command-line\nfunctionality:\n\n    rake annotate_models                          # Add schema information (as comments) to model and fixture files\n    rake annotate_routes                          # Adds the route map to routes.rb\n    rake remove_annotation                        # Remove schema information from model and fixture files\n\nBy default, once you've generated a configuration file, annotate will be\nexecuted whenever you run `rake db:migrate` (but only in development mode).\nIf you want to disable this behavior permanently,\nedit the `.rake` file and change:\n\n```ruby\n    'skip_on_db_migrate'   =\u003e 'false',\n```\n\nTo:\n\n```ruby\n    'skip_on_db_migrate'   =\u003e 'true',\n```\n\nIf you want to run `rake db:migrate` as a one-off without running annotate,\nyou can do so with a simple environment variable, instead of editing the\n`.rake` file:\n\n    ANNOTATE_SKIP_ON_DB_MIGRATE=1 rake db:migrate\n\n## Options\n\n    Usage: annotate [options] [model_file]*\n            --additional-file-patterns   Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)\n        -d, --delete                     Remove annotations from all model files or the routes.rb file\n        -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)\n            --position\n            --pc, --position-in-class [before|top|after|bottom]\n                                         Place the annotations at the top (before) or the bottom (after) of the model file\n            --pf, --position-in-factory [before|top|after|bottom]\n                                         Place the annotations at the top (before) or the bottom (after) of any factory files\n            --px, --position-in-fixture [before|top|after|bottom]\n                                         Place the annotations at the top (before) or the bottom (after) of any fixture files\n            --pt, --position-in-test [before|top|after|bottom]\n                                         Place the annotations at the top (before) or the bottom (after) of any test files\n            --pr, --position-in-routes [before|top|after|bottom]\n                                         Place the annotations at the top (before) or the bottom (after) of the routes.rb file\n            --ps, --position-in-serializer [before|top|after|bottom]\n                                         Place the annotations at the top (before) or the bottom (after) of the serializer files\n            --w, --wrapper STR           Wrap annotation with the text passed as parameter.\n                                         If --w option is used, the same text will be used as opening and closing\n            --wo, --wrapper-open STR     Annotation wrapper opening.\n            --wc, --wrapper-close STR    Annotation wrapper closing\n        -r, --routes                     Annotate routes.rb with the output of 'rake routes'\n            --models                     Annotate ActiveRecord models\n        -a, --active-admin               Annotate active_admin models\n        -v, --version                    Show the current version of this gem\n        -m, --show-migration             Include the migration version number in the annotation\n        -c, --show-check-constraints     List the table's check constraints in the annotation\n        -k, --show-foreign-keys          List the table's foreign key constraints in the annotation\n            --ck, --complete-foreign-keys\n                                         Complete foreign key names in the annotation\n        -i, --show-indexes               List the table's database indexes in the annotation\n        -s, --simple-indexes             Concat the column's related indexes in the annotation\n            --model-dir dir              Annotate model files stored in dir rather than app/models, separate multiple dirs with commas\n            --root-dir dir               Annotate files stored within root dir projects, separate multiple dirs with commas\n            --ignore-model-subdirects    Ignore subdirectories of the models directory\n            --sort                       Sort columns alphabetically, rather than in creation order\n            --classified-sort            Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns\n        -R, --require path               Additional file to require before loading models, may be used multiple times\n        -e [tests,fixtures,factories,serializers],\n            --exclude                    Do not annotate fixtures, test files, factories, and/or serializers\n        -f [bare|rdoc|yard|markdown],    Render Schema Infomation as plain/RDoc/YARD/Markdown\n            --format\n            --force                      Force new annotations even if there are no changes.\n            --frozen                     Do not allow to change annotations. Exits non-zero if there are going to be changes to files.\n            --timestamp                  Include timestamp in (routes) annotation\n            --trace                      If unable to annotate a file, print the full stack trace, not just the exception message.\n        -I, --ignore-columns REGEX       don't annotate columns that match a given REGEX (e.g. `annotate -I '^(id|updated_at|created_at)'`)\n            --ignore-routes REGEX        don't annotate routes that match a given REGEX (e.g. `annotate -I '(mobile|resque|pghero)'`)_\n            --hide-limit-column-types VALUES\n                                         don't show limit for given column types, separated by commas (e.g. `integer,boolean,text`)\n            --hide-default-column-types VALUES\n                                         don't show default for given column types, separated by commas (e.g. `json,jsonb,hstore`)\n            --ignore-unknown-models      don't display warnings for bad model files\n            --with-comment               include database comments in model annotations\n            --with-comment-column        include database comments in model annotations, as its own column, after all others\n\n### Option: `additional_file_patterns`\n\nCLI: `--additional-file-patterns`\u003cbr\u003e\nRuby: `:additional_file_patterns`\n\nProvide additional paths for the gem to annotate.  These paths can include\nglobs. It is recommended to use absolute paths.  Here are some examples:\n\n*   `/app/lib/decorates/%MODEL_NAME%/*.rb`\n*   `/app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb`\n*   `/app/lib/forms/%TABLE_NAME%/*.rb`\n\n\nThe appropriate model will be inferred using the `%*%` syntax, annotating any\nmatching files. It works with existing filename resolutions (options for which\ncan be found in the `resolve_filename` method of `annotate_models.rb`).\n\nWhen using in a Rails config, you can use the following:\n\n`File.join(Rails.application.root,\n'app/lib/forms/%PLURALIZED_MODEL_NAME%/***/**.rb')`\n\n## Sorting\n\nBy default, columns will be sorted in database order (i.e. the order in which\nmigrations were run).\n\nIf you prefer to sort alphabetically so that the results of annotation are\nconsistent regardless of what order migrations are executed in, use `--sort`.\n\n## Markdown\n\nThe format produced is actually MultiMarkdown, making use of the syntax\nextension for tables.  It's recommended you use `kramdown` as your parser if\nyou want to use this format.  If you're using `yard` to generate\ndocumentation, specify a format of markdown with `kramdown` as the provider by\nadding this to your `.yardopts` file:\n\n    --markup markdown\n    --markup-provider kramdown\n\nBe sure to add this to your `Gemfile` as well:\n\n    gem 'kramdown', groups =\u003e [:development], require =\u003e false\n\n## WARNING\n\n**Don't add text after an automatically-created comment block.** This tool\nwill blow away the initial/final comment block in your models if it looks like\nit was previously added by this gem.\n\nBe sure to check the changes that this tool makes! If you are using Git, you\nmay simply check your project's status after running `annotate`:\n\n    $ git status\n\nIf you are not using a VCS (like Git, Subversion or similar), please tread\nextra carefully, and consider using one.\n\n## Links\n\n*   Factory Bot: http://github.com/thoughtbot/factory_bot\n*   Object Daddy: http://github.com/flogic/object_daddy\n*   Machinist: http://github.com/notahat/machinist\n*   Fabrication: http://github.com/paulelliott/fabrication\n*   SpatialAdapter: http://github.com/pdeffendol/spatial_adapter\n*   PostgisAdapter: http://github.com/nofxx/postgis_adapter\n*   PostGISAdapter: https://github.com/dazuma/activerecord-postgis-adapter\n\n\n## License\n\nReleased under the same license as Ruby. No Support. No Warranty.\n\n## Authors\n\n[See AUTHORS.md](AUTHORS.md).\n","funding_links":[],"categories":["Ruby","Documentation","Gems","WebSocket","ActiveRecord","Awesome Ruby CLIs"],"sub_categories":["ActiveRecord","Articles","Generating"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctran%2Fannotate_models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctran%2Fannotate_models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctran%2Fannotate_models/lists"}