annotate 2.7.5 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{AUTHORS.rdoc → AUTHORS.md} +2 -2
- data/CHANGELOG.md +326 -0
- data/{README.rdoc → README.md} +154 -100
- data/RELEASE.md +19 -0
- data/annotate.gemspec +11 -27
- data/bin/annotate +7 -191
- data/lib/annotate/annotate_models/file_patterns.rb +127 -0
- data/lib/annotate/annotate_models.rb +183 -188
- data/lib/annotate/annotate_routes/header_generator.rb +113 -0
- data/lib/annotate/annotate_routes/helpers.rb +69 -0
- data/lib/annotate/annotate_routes.rb +69 -200
- data/lib/annotate/constants.rb +38 -0
- data/lib/annotate/helpers.rb +30 -0
- data/lib/annotate/parser.rb +303 -0
- data/lib/annotate/version.rb +1 -1
- data/lib/annotate.rb +23 -82
- data/lib/generators/annotate/templates/auto_annotate_models.rake +45 -41
- data/lib/tasks/annotate_models.rake +37 -35
- data/lib/tasks/annotate_models_migrate.rake +17 -4
- data/lib/tasks/annotate_routes.rake +12 -6
- data/potato.md +41 -0
- metadata +25 -17
- data/CHANGELOG.rdoc +0 -220
- data/TODO.rdoc +0 -11
data/{README.rdoc → README.md}
RENAMED
@@ -1,15 +1,14 @@
|
|
1
|
-
|
1
|
+
## Annotate (aka AnnotateModels)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
[](http://badge.fury.io/rb/annotate)
|
4
|
+
[](https://rubygems.org/gems/annotate)
|
5
|
+
[](https://travis-ci.org/ctran/annotate_models)
|
6
|
+
[](https://github.com/ctran/annotate_models/actions?workflow=CI)
|
7
|
+
[](https://coveralls.io/r/ctran/annotate_models?branch=develop)
|
8
|
+
[](https://codeclimate.com/github/ctran/annotate_models)
|
9
|
+
[](http://inch-ci.org/github/ctran/annotate_models)
|
10
10
|
|
11
|
-
Add a comment summarizing the current schema to the top or bottom of each of
|
12
|
-
your...
|
11
|
+
Add a comment summarizing the current schema to the top or bottom of each of your...
|
13
12
|
|
14
13
|
- ActiveRecord models
|
15
14
|
- Fixture files
|
@@ -17,53 +16,85 @@ your...
|
|
17
16
|
- Object Daddy exemplars
|
18
17
|
- Machinist blueprints
|
19
18
|
- Fabrication fabricators
|
20
|
-
- Thoughtbot's factory_bot factories, i.e. the (spec|test)/factories/<model>_factory.rb files
|
21
|
-
- routes.rb file (for Rails projects)
|
19
|
+
- Thoughtbot's factory_bot factories, i.e. the `(spec|test)/factories/<model>_factory.rb` files
|
20
|
+
- `routes.rb` file (for Rails projects)
|
21
|
+
|
22
22
|
|
23
23
|
The schema comment looks like this:
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
```ruby
|
26
|
+
# == Schema Info
|
27
|
+
#
|
28
|
+
# Table name: line_items
|
29
|
+
#
|
30
|
+
# id :integer(11) not null, primary key
|
31
|
+
# quantity :integer(11) not null
|
32
|
+
# product_id :integer(11) not null
|
33
|
+
# unit_price :float
|
34
|
+
# order_id :integer(11)
|
35
|
+
#
|
36
|
+
|
37
|
+
class LineItem < ActiveRecord::Base
|
38
|
+
belongs_to :product
|
39
|
+
. . .
|
40
|
+
```
|
41
|
+
|
42
|
+
It also annotates geometrical columns, `geom` type and `srid`,
|
43
|
+
when using `SpatialAdapter`, `PostgisAdapter` or `PostGISAdapter`:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
# == Schema Info
|
47
|
+
#
|
48
|
+
# Table name: trips
|
49
|
+
#
|
50
|
+
# local :geometry point, 4326
|
51
|
+
# path :geometry line_string, 4326
|
52
|
+
```
|
53
|
+
|
54
|
+
Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake routes`.
|
35
55
|
|
36
|
-
class LineItem < ActiveRecord::Base
|
37
|
-
belongs_to :product
|
38
|
-
. . .
|
39
56
|
|
40
|
-
|
41
|
-
+SpatialAdapter+, +PostgisAdapter+ or +PostGISAdapter+:
|
57
|
+
## Upgrading to 3.X and annotate models not working?
|
42
58
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
# local :geometry point, 4326
|
48
|
-
# path :geometry line_string, 4326
|
59
|
+
In versions 2.7.X the annotate gem defaulted to annotating models if no arguments were passed in.
|
60
|
+
The annotate gem by default would not allow for routes and models to be annotated together.
|
61
|
+
A [change was added in #647](https://github.com/ctran/annotate_models/pull/647).
|
62
|
+
You [can read more here](https://github.com/ctran/annotate_models/issues/663).
|
49
63
|
|
50
|
-
|
51
|
-
<code>rake routes</code>.
|
64
|
+
There are a few ways of fixing this:
|
52
65
|
|
66
|
+
- If using CLI explicitly pass in models flag using `--models`
|
53
67
|
|
54
|
-
|
68
|
+
OR
|
69
|
+
|
70
|
+
a) Running `rails g annotate:install` will overwrite your defaults with the annotating `models` option set to `'true'`.
|
71
|
+
|
72
|
+
b) In `lib/tasks/auto_annotate_models.rake` add the `models` key-value option:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Annotate.set_defaults(
|
76
|
+
...
|
77
|
+
'models' => 'true',
|
78
|
+
...
|
79
|
+
```
|
80
|
+
|
81
|
+
## Install
|
55
82
|
|
56
83
|
Into Gemfile from rubygems.org:
|
57
84
|
|
58
|
-
|
59
|
-
|
60
|
-
|
85
|
+
```ruby
|
86
|
+
group :development do
|
87
|
+
gem 'annotate'
|
88
|
+
end
|
89
|
+
```
|
61
90
|
|
62
91
|
Into Gemfile from Github:
|
63
92
|
|
64
|
-
|
65
|
-
|
66
|
-
|
93
|
+
```ruby
|
94
|
+
group :development do
|
95
|
+
gem 'annotate', git: 'https://github.com/ctran/annotate_models.git'
|
96
|
+
end
|
97
|
+
```
|
67
98
|
|
68
99
|
Into environment gems from rubygems.org:
|
69
100
|
|
@@ -73,15 +104,14 @@ Into environment gems from Github checkout:
|
|
73
104
|
|
74
105
|
git clone https://github.com/ctran/annotate_models.git annotate_models
|
75
106
|
cd annotate_models
|
76
|
-
rake
|
77
|
-
gem install
|
78
|
-
|
107
|
+
rake gem
|
108
|
+
gem install dist/annotate-*.gem
|
79
109
|
|
80
|
-
|
110
|
+
## Usage
|
81
111
|
|
82
|
-
(If you used the Gemfile install, prefix the below commands with
|
112
|
+
(If you used the Gemfile install, prefix the below commands with `bundle exec`.)
|
83
113
|
|
84
|
-
|
114
|
+
### Usage in Rails
|
85
115
|
|
86
116
|
To annotate all your models, tests, fixtures, and factories:
|
87
117
|
|
@@ -90,11 +120,11 @@ To annotate all your models, tests, fixtures, and factories:
|
|
90
120
|
|
91
121
|
To annotate just your models, tests, and factories:
|
92
122
|
|
93
|
-
annotate --exclude fixtures
|
123
|
+
annotate --models --exclude fixtures
|
94
124
|
|
95
125
|
To annotate just your models:
|
96
126
|
|
97
|
-
annotate --
|
127
|
+
annotate --models
|
98
128
|
|
99
129
|
To annotate routes.rb:
|
100
130
|
|
@@ -108,26 +138,28 @@ To remove routes.rb annotations:
|
|
108
138
|
|
109
139
|
annotate --routes --delete
|
110
140
|
|
111
|
-
To automatically annotate every time you run
|
141
|
+
To automatically annotate every time you run `db:migrate`,
|
142
|
+
either run `rails g annotate:install`
|
143
|
+
or add `Annotate.load_tasks` to your `Rakefile`.
|
112
144
|
|
113
|
-
|
145
|
+
See the [configuration in Rails](#configuration-in-rails) section for more info.
|
114
146
|
|
115
|
-
|
116
|
-
probably need to explicitly set one or more +--require+ option(s), and/or one
|
117
|
-
or more +--model-dir+ options to inform annotate about the structure of your
|
118
|
-
project and help it bootstrap and load the relevant code.
|
147
|
+
### Usage Outside of Rails
|
119
148
|
|
149
|
+
Everything above applies, except that `--routes` is not meaningful,
|
150
|
+
and you will probably need to explicitly set one or more `--require` option(s), and/or one or more `--model-dir` options
|
151
|
+
to inform `annotate` about the structure of your project and help it bootstrap and load the relevant code.
|
120
152
|
|
121
|
-
|
153
|
+
## Configuration
|
122
154
|
|
123
155
|
If you want to always skip annotations on a particular model, add this string
|
124
156
|
anywhere in the file:
|
125
157
|
|
126
158
|
# -*- SkipSchemaAnnotations
|
127
159
|
|
128
|
-
|
160
|
+
### Configuration in Rails
|
129
161
|
|
130
|
-
To generate a configuration file (in the form of a
|
162
|
+
To generate a configuration file (in the form of a `.rake` file), to set
|
131
163
|
default options:
|
132
164
|
|
133
165
|
rails g annotate:install
|
@@ -135,7 +167,7 @@ default options:
|
|
135
167
|
Edit this file to control things like output format, where annotations are
|
136
168
|
added (top or bottom of file), and in which artifacts.
|
137
169
|
|
138
|
-
The generated rakefile
|
170
|
+
The generated rakefile `lib/tasks/auto_annotate_models.rake` also contains
|
139
171
|
`Annotate.load_tasks`. This adds a few rake tasks which duplicate command-line
|
140
172
|
functionality:
|
141
173
|
|
@@ -144,26 +176,30 @@ functionality:
|
|
144
176
|
rake remove_annotation # Remove schema information from model and fixture files
|
145
177
|
|
146
178
|
By default, once you've generated a configuration file, annotate will be
|
147
|
-
executed whenever you run
|
148
|
-
If you want to disable this behavior permanently,
|
149
|
-
change:
|
179
|
+
executed whenever you run `rake db:migrate` (but only in development mode).
|
180
|
+
If you want to disable this behavior permanently,
|
181
|
+
edit the `.rake` file and change:
|
150
182
|
|
183
|
+
```ruby
|
151
184
|
'skip_on_db_migrate' => 'false',
|
185
|
+
```
|
152
186
|
|
153
187
|
To:
|
154
188
|
|
189
|
+
```ruby
|
155
190
|
'skip_on_db_migrate' => 'true',
|
191
|
+
```
|
156
192
|
|
157
|
-
If you want to run
|
193
|
+
If you want to run `rake db:migrate` as a one-off without running annotate,
|
158
194
|
you can do so with a simple environment variable, instead of editing the
|
159
|
-
|
195
|
+
`.rake` file:
|
160
196
|
|
161
197
|
ANNOTATE_SKIP_ON_DB_MIGRATE=1 rake db:migrate
|
162
198
|
|
163
|
-
|
164
|
-
== Options
|
199
|
+
## Options
|
165
200
|
|
166
201
|
Usage: annotate [options] [model_file]*
|
202
|
+
--additional-file-patterns Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)
|
167
203
|
-d, --delete Remove annotations from all model files or the routes.rb file
|
168
204
|
-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)
|
169
205
|
--position
|
@@ -184,6 +220,7 @@ you can do so with a simple environment variable, instead of editing the
|
|
184
220
|
--wo, --wrapper-open STR Annotation wrapper opening.
|
185
221
|
--wc, --wrapper-close STR Annotation wrapper closing
|
186
222
|
-r, --routes Annotate routes.rb with the output of 'rake routes'
|
223
|
+
--models Annotate ActiveRecord models
|
187
224
|
-a, --active-admin Annotate active_admin models
|
188
225
|
-v, --version Show the current version of this gem
|
189
226
|
-m, --show-migration Include the migration version number in the annotation
|
@@ -200,78 +237,95 @@ you can do so with a simple environment variable, instead of editing the
|
|
200
237
|
-R, --require path Additional file to require before loading models, may be used multiple times
|
201
238
|
-e [tests,fixtures,factories,serializers],
|
202
239
|
--exclude Do not annotate fixtures, test files, factories, and/or serializers
|
203
|
-
-f [bare|rdoc|markdown],
|
240
|
+
-f [bare|rdoc|yard|markdown], Render Schema Infomation as plain/RDoc/YARD/Markdown
|
204
241
|
--format
|
205
242
|
--force Force new annotations even if there are no changes.
|
206
243
|
--frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files.
|
207
244
|
--timestamp Include timestamp in (routes) annotation
|
208
245
|
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
|
209
|
-
-I, --ignore-columns REGEX don't annotate columns that match a given REGEX (
|
210
|
-
--ignore-routes REGEX don't annotate routes that match a given REGEX (
|
246
|
+
-I, --ignore-columns REGEX don't annotate columns that match a given REGEX (e.g. `annotate -I '^(id|updated_at|created_at)'`)
|
247
|
+
--ignore-routes REGEX don't annotate routes that match a given REGEX (e.g. `annotate -I '(mobile|resque|pghero)'`)_
|
211
248
|
--hide-limit-column-types VALUES
|
212
|
-
don't show limit for given column types, separated by commas (
|
249
|
+
don't show limit for given column types, separated by commas (e.g. `integer,boolean,text`)
|
213
250
|
--hide-default-column-types VALUES
|
214
|
-
don't show default for given column types, separated by commas (
|
251
|
+
don't show default for given column types, separated by commas (e.g. `json,jsonb,hstore`)
|
215
252
|
--ignore-unknown-models don't display warnings for bad model files
|
216
253
|
--with-comment include database comments in model annotations
|
217
254
|
|
255
|
+
### Option: `additional_file_patterns`
|
256
|
+
|
257
|
+
CLI: `--additional-file-patterns`<br>
|
258
|
+
Ruby: `:additional_file_patterns`
|
259
|
+
|
260
|
+
Provide additional paths for the gem to annotate. These paths can include
|
261
|
+
globs. It is recommended to use absolute paths. Here are some examples:
|
262
|
+
|
263
|
+
* `/app/lib/decorates/%MODEL_NAME%/*.rb`
|
264
|
+
* `/app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb`
|
265
|
+
* `/app/lib/forms/%TABLE_NAME%/*.rb`
|
266
|
+
|
218
267
|
|
268
|
+
The appropriate model will be inferred using the `%*%` syntax, annotating any
|
269
|
+
matching files. It works with existing filename resolutions (options for which
|
270
|
+
can be found in the `resolve_filename` method of `annotate_models.rb`).
|
219
271
|
|
220
|
-
|
272
|
+
When using in a Rails config, you can use the following:
|
273
|
+
|
274
|
+
`File.join(Rails.application.root,
|
275
|
+
'app/lib/forms/%PLURALIZED_MODEL_NAME%/***/**.rb')`
|
276
|
+
|
277
|
+
## Sorting
|
221
278
|
|
222
279
|
By default, columns will be sorted in database order (i.e. the order in which
|
223
280
|
migrations were run).
|
224
281
|
|
225
|
-
If you prefer to sort alphabetically so that the results of
|
226
|
-
|
227
|
-
use +--sort+.
|
282
|
+
If you prefer to sort alphabetically so that the results of annotation are
|
283
|
+
consistent regardless of what order migrations are executed in, use `--sort`.
|
228
284
|
|
229
|
-
|
230
|
-
== Markdown
|
285
|
+
## Markdown
|
231
286
|
|
232
287
|
The format produced is actually MultiMarkdown, making use of the syntax
|
233
|
-
extension for tables. It's recommended you use
|
234
|
-
you want to use this format. If you're using
|
235
|
-
specify a format of markdown with
|
236
|
-
your
|
288
|
+
extension for tables. It's recommended you use `kramdown` as your parser if
|
289
|
+
you want to use this format. If you're using `yard` to generate
|
290
|
+
documentation, specify a format of markdown with `kramdown` as the provider by
|
291
|
+
adding this to your `.yardopts` file:
|
237
292
|
|
238
293
|
--markup markdown
|
239
294
|
--markup-provider kramdown
|
240
295
|
|
241
|
-
Be sure to add this to your
|
242
|
-
|
243
|
-
gem 'kramdown', :groups => [:development], :require => false
|
296
|
+
Be sure to add this to your `Gemfile` as well:
|
244
297
|
|
298
|
+
gem 'kramdown', groups => [:development], require => false
|
245
299
|
|
246
|
-
|
300
|
+
## WARNING
|
247
301
|
|
248
|
-
|
302
|
+
**Don't add text after an automatically-created comment block.** This tool
|
249
303
|
will blow away the initial/final comment block in your models if it looks like
|
250
304
|
it was previously added by this gem.
|
251
305
|
|
252
|
-
Be sure to check the changes that this tool makes! If you are using Git,
|
253
|
-
|
306
|
+
Be sure to check the changes that this tool makes! If you are using Git, you
|
307
|
+
may simply check your project's status after running `annotate`:
|
254
308
|
|
255
309
|
$ git status
|
256
310
|
|
257
311
|
If you are not using a VCS (like Git, Subversion or similar), please tread
|
258
312
|
extra carefully, and consider using one.
|
259
313
|
|
260
|
-
|
314
|
+
## Links
|
261
315
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
316
|
+
* Factory Bot: http://github.com/thoughtbot/factory_bot
|
317
|
+
* Object Daddy: http://github.com/flogic/object_daddy
|
318
|
+
* Machinist: http://github.com/notahat/machinist
|
319
|
+
* Fabrication: http://github.com/paulelliott/fabrication
|
320
|
+
* SpatialAdapter: http://github.com/pdeffendol/spatial_adapter
|
321
|
+
* PostgisAdapter: http://github.com/nofxx/postgis_adapter
|
322
|
+
* PostGISAdapter: https://github.com/dazuma/activerecord-postgis-adapter
|
269
323
|
|
270
324
|
|
271
|
-
|
325
|
+
## License
|
272
326
|
|
273
327
|
Released under the same license as Ruby. No Support. No Warranty.
|
274
328
|
|
275
|
-
|
329
|
+
## Authors
|
276
330
|
|
277
|
-
|
331
|
+
[See AUTHORS.md](AUTHORS.md).
|
data/RELEASE.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## Prerequisite
|
2
|
+
|
3
|
+
- Install "git-flow" (`brew install git-flow`)
|
4
|
+
- Install "bump" gem (`gem install bump`)
|
5
|
+
|
6
|
+
|
7
|
+
## Perform a release
|
8
|
+
|
9
|
+
- `git flow release start <release>`
|
10
|
+
- Update the `CHANGELOG.md` file
|
11
|
+
- `bump current`
|
12
|
+
- `bump patch`
|
13
|
+
- `rm -rf dist`
|
14
|
+
- `rake spec`
|
15
|
+
- `rake gem`
|
16
|
+
- `git flow release finish <release>`
|
17
|
+
|
18
|
+
- `rake gem:publish`
|
19
|
+
|
data/annotate.gemspec
CHANGED
@@ -7,42 +7,26 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.name = 'annotate'
|
8
8
|
s.version = Annotate.version
|
9
9
|
|
10
|
-
s.required_ruby_version = '>= 2.
|
10
|
+
s.required_ruby_version = '>= 2.4.0'
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ['Alex Chaffee', 'Cuong Tran', 'Marcos Piccinini', 'Turadg Aleahmad', 'Jon Frisby']
|
13
13
|
s.description = 'Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema.'
|
14
14
|
s.email = ['alex@stinky.com', 'cuong.tran@gmail.com', 'x@nofxx.com', 'turadg@aleahmad.net', 'jon@cloudability.com']
|
15
15
|
s.executables = ['annotate']
|
16
|
-
s.extra_rdoc_files = ['README.
|
17
|
-
s.files =
|
18
|
-
|
19
|
-
'CHANGELOG.rdoc',
|
20
|
-
'LICENSE.txt',
|
21
|
-
'README.rdoc',
|
22
|
-
'TODO.rdoc',
|
23
|
-
'annotate.gemspec',
|
24
|
-
'bin/annotate',
|
25
|
-
'lib/annotate.rb',
|
26
|
-
'lib/annotate/active_record_patch.rb',
|
27
|
-
'lib/annotate/annotate_models.rb',
|
28
|
-
'lib/annotate/annotate_routes.rb',
|
29
|
-
'lib/annotate/tasks.rb',
|
30
|
-
'lib/annotate/version.rb',
|
31
|
-
'lib/generators/annotate/USAGE',
|
32
|
-
'lib/generators/annotate/install_generator.rb',
|
33
|
-
'lib/generators/annotate/templates/auto_annotate_models.rake',
|
34
|
-
'lib/tasks/annotate_models.rake',
|
35
|
-
'lib/tasks/annotate_routes.rake',
|
36
|
-
'lib/tasks/annotate_models_migrate.rake'
|
37
|
-
]
|
38
|
-
s.homepage = 'http://github.com/ctran/annotate_models'
|
16
|
+
s.extra_rdoc_files = ['README.md', 'CHANGELOG.md']
|
17
|
+
s.files = `git ls-files -z LICENSE.txt *.md *.gemspec bin lib`.split("\x0")
|
18
|
+
s.homepage = 'https://github.com/ctran/annotate_models'
|
39
19
|
s.licenses = ['Ruby']
|
40
20
|
s.require_paths = ['lib']
|
41
|
-
s.rubyforge_project = 'annotate'
|
42
21
|
s.rubygems_version = '2.1.11'
|
43
22
|
s.summary = 'Annotates Rails Models, routes, fixtures, and others based on the database schema.'
|
44
23
|
|
45
24
|
s.specification_version = 4 if s.respond_to? :specification_version
|
46
|
-
s.add_runtime_dependency(%q<rake>,
|
47
|
-
s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '<
|
25
|
+
s.add_runtime_dependency(%q<rake>, '>= 10.4', '< 14.0')
|
26
|
+
s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 8.0'])
|
27
|
+
|
28
|
+
s.metadata = {
|
29
|
+
"bug_tracker_uri" => "https://github.com/ctran/annotate_models/issues/",
|
30
|
+
"source_code_uri" => "https://github.com/ctran/annotate_models.git"
|
31
|
+
}
|
48
32
|
end
|