annotate 2.5.0 → 2.6.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/{History.txt → CHANGELOG.rdoc} +62 -6
- data/README.rdoc +129 -39
- data/TODO.rdoc +12 -0
- data/annotate.gemspec +38 -0
- data/bin/annotate +66 -26
- data/lib/annotate.rb +143 -10
- data/lib/annotate/active_record_patch.rb +1 -1
- data/lib/annotate/annotate_models.rb +152 -98
- data/lib/annotate/annotate_routes.rb +126 -20
- data/lib/annotate/version.rb +1 -1
- data/lib/generators/{annotate_models → annotate}/USAGE +1 -1
- data/lib/generators/{annotate_models → annotate}/install_generator.rb +2 -2
- data/lib/generators/annotate/templates/auto_annotate_models.rake +34 -0
- data/lib/tasks/annotate_models.rake +21 -16
- data/lib/tasks/annotate_routes.rake +17 -2
- metadata +42 -29
- data/lib/generators/annotate_models/templates/auto_annotate_models.rake +0 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9cf1dc6bc654533120158f1a4e03caffd4dcb429
|
4
|
+
data.tar.gz: 12c3f503657c5d96ae02675a47ea5420956918ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 69f28f89810d03767192f46583b550a34dac95332fd7d5fe545e57d5405fa5e97664966d2b0700a67eb6a56096a4085db1d1d557773d7947789c017ed7ac3de1
|
7
|
+
data.tar.gz: d613cad136a5a6941bb33563c777d835a9dfa8b9db7f1c0d9851afbe4976b9763ad279e30515d48fe3304e4241fa9af3c463a94244da13fad6117abf406c20a3
|
@@ -1,3 +1,51 @@
|
|
1
|
+
== 2.6.0.beta2
|
2
|
+
|
3
|
+
* support for composite_primary_keys (garysweaver)
|
4
|
+
* bug fix for annotate_one_file (vlado)
|
5
|
+
|
6
|
+
== 2.6.0.beta1
|
7
|
+
|
8
|
+
* It's now possible to use Annotate in standalone ActiveRecord (non-Rails)
|
9
|
+
projects again.
|
10
|
+
* Adding note that Markdown is actually MultiMarkdown, and recommending the use
|
11
|
+
of the `kramdown` engine for parsing it.
|
12
|
+
* Improved Markdown formatting considerably.
|
13
|
+
* Bugfix: Needed to use inline-code tag for column and table names, otherwise
|
14
|
+
underscores would cause havok with the formatting.
|
15
|
+
* Bugfix: Markdown syntax was incorrect (can't have trailing spaces before the
|
16
|
+
closing marker for an emphasis tag).
|
17
|
+
* Bugfix: Remove-annotations wasn't properly finding test/spec files, and
|
18
|
+
wasn't even looking for FactoryGirl factories under the new naming
|
19
|
+
convention.
|
20
|
+
* Bugfix: Load the Rakefile from the current directory, not the first Rakefile
|
21
|
+
in our load path.
|
22
|
+
* Added support for new FactoryGirl naming convention.
|
23
|
+
* Fix behavior of route annotations in newer versions of Rake that don't spit
|
24
|
+
out the CWD as their first line of output.
|
25
|
+
* Overhauled integration testing system to be much easier to work with, better
|
26
|
+
compartmentalized, and so forth -- at the cost that you must be using RVM to
|
27
|
+
utilize it. (It'll spit out appropriate pending messages if you don't.)
|
28
|
+
Also includes a mode for "tinkering" by hand with a scenario, and won't let
|
29
|
+
you run it through rspect if the repo is in a dirty state. Added appropriate
|
30
|
+
rake tasks to help with all of this.
|
31
|
+
* Routes can now be appended, pre-pended, or removed -- and do sane things in
|
32
|
+
all cases.
|
33
|
+
* Expose all `position_*` variables as CLI params.
|
34
|
+
* Make `ENV ['position']` work as a default for all the `ENV ['position_*']`
|
35
|
+
variables.
|
36
|
+
* Make rake tasks more resilient to unusual circumstances / code loading
|
37
|
+
behavior.
|
38
|
+
* Resolve annotate vs. annotate_models ambiguity once and for all by settling
|
39
|
+
on `annotate_models` _and_ `annotate_routes`. This avoids a name collision
|
40
|
+
with RMagick while not needlessly overloading the term.
|
41
|
+
* Fixed that schema kept prepending additional newlines
|
42
|
+
* Updates to make annotate smarter about when to touch a model
|
43
|
+
* Recognize column+type, and don't change a file unless the column+type
|
44
|
+
combination of the new schema are different than that of the old (i.e., don't
|
45
|
+
regenerate if columns happen to be in a different order. That's just how life
|
46
|
+
is sometimes)
|
47
|
+
* Change annotate to use options hash instead of ENV.
|
48
|
+
|
1
49
|
== 2.5.0
|
2
50
|
|
3
51
|
* Works better with Rails 3
|
@@ -6,17 +54,23 @@
|
|
6
54
|
* Recognize column+type, and don't change a file unless the column+type combination of the new schema are different than that of the old (i.e., don't regenerate if columns happen to be in a different order. That's just how life is sometimes.)
|
7
55
|
* Grab old specification even if it has \r\n as line endings rather than pure \ns
|
8
56
|
* Various warning and specification fixes
|
9
|
-
* Fix "no such file to load -- annotate/annotate_models (MissingSourceFile)"
|
10
|
-
|
57
|
+
* Fix "no such file to load -- annotate/annotate_models (MissingSourceFile)"
|
58
|
+
error (require statements in tasks now use full path to lib files)
|
59
|
+
* warn about macros, to mitigate when we're included during a production run,
|
60
|
+
not just a rakefile run -- possibly at the expense of too much noise
|
11
61
|
* Adding rake as a runtime dependency
|
12
|
-
* If the schema is already in the model file, it will be replaced into the same
|
13
|
-
|
62
|
+
* If the schema is already in the model file, it will be replaced into the same
|
63
|
+
location. If it didn't previously exist, it'll be placed according to the
|
64
|
+
"position", as before.
|
65
|
+
* Allow task loading from Rakefile for gems (plugin installation already
|
66
|
+
auto-detects).
|
14
67
|
* Add skip_on_db_migrate option as well for people that don't want it
|
15
68
|
* Fix options parsing to convert strings to proper booleans
|
16
69
|
* Add support for Fabrication fabricators
|
17
70
|
* Leave magic encoding comment intact
|
18
71
|
* Fix issue #14 - RuntimeError: Already memoized
|
19
72
|
* Count a model as 'annotated' if any of its tests/fixtures are annotated
|
73
|
+
* Support FactoryGirl
|
20
74
|
* Support :change migrations (Rails 3.1)
|
21
75
|
* Allow models with non-standard capitalization
|
22
76
|
* Widen type column so we can handle longtexts with chopping things off.
|
@@ -27,7 +81,7 @@
|
|
27
81
|
'# -*- SkipSchemaAnnotations' anywhere in the file.
|
28
82
|
* Don't show column limits for integer and boolean types.
|
29
83
|
* Add sorting for columns and indexes. (Helpful for out-of-order migration
|
30
|
-
execution
|
84
|
+
execution. Use --sort if you want this.)
|
31
85
|
* Annotate unit tests in subfolders.
|
32
86
|
* Add generator to install rakefile that automatically annotates on db:migrate.
|
33
87
|
* Correct Gemfile to clarify which environments need which gems.
|
@@ -38,6 +92,7 @@
|
|
38
92
|
non-standard capitalization.
|
39
93
|
Note that this still requires that the inflector be configured to understand
|
40
94
|
the special case.
|
95
|
+
* Shore up test cases a bit.
|
41
96
|
* Merge against many of the older branches on Github whose functionality is
|
42
97
|
already reflected to reduce confusion about what is and is not implemented
|
43
98
|
here.
|
@@ -72,7 +127,8 @@
|
|
72
127
|
|
73
128
|
== 2.4.0 2009-12-13
|
74
129
|
|
75
|
-
* Incorporated lots of patches from the Github community, including support for
|
130
|
+
* Incorporated lots of patches from the Github community, including support for
|
131
|
+
Blueprints fixtures
|
76
132
|
* Several bug fixes
|
77
133
|
|
78
134
|
== 2.1 2009-10-18
|
data/README.rdoc
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
== Annotate (aka AnnotateModels)
|
2
2
|
|
3
|
-
|
3
|
+
IMPORTANT: If you're upgrading from a previous version, including 2.5.0,
|
4
|
+
re-run the generator task!
|
5
|
+
|
6
|
+
Add a comment summarizing the current schema to the top or bottom of each of
|
7
|
+
your...
|
4
8
|
|
5
9
|
- ActiveRecord models
|
6
10
|
- Fixture files
|
@@ -9,7 +13,7 @@ Add a comment summarizing the current schema to the top or bottom of each of you
|
|
9
13
|
- Machinist blueprints
|
10
14
|
- Fabrication fabricators
|
11
15
|
- Thoughtbot's factory_girl factories, i.e. the (spec|test)/factories/<model>_factory.rb files
|
12
|
-
- routes.rb file
|
16
|
+
- routes.rb file (for Rails projects)
|
13
17
|
|
14
18
|
The schema comment looks like this:
|
15
19
|
|
@@ -28,7 +32,8 @@ The schema comment looks like this:
|
|
28
32
|
belongs_to :product
|
29
33
|
. . .
|
30
34
|
|
31
|
-
It also annotates geometrical columns, geom type and srid, when using
|
35
|
+
It also annotates geometrical columns, geom type and srid, when using
|
36
|
+
`SpatialAdapter` or `PostgisAdapter`:
|
32
37
|
|
33
38
|
# == Schema Info
|
34
39
|
#
|
@@ -37,9 +42,11 @@ It also annotates geometrical columns, geom type and srid, when using SpatialAda
|
|
37
42
|
# local :geometry point, 4326
|
38
43
|
# path :geometry line_string, 4326
|
39
44
|
|
40
|
-
Also, if you pass the -r option, it'll annotate routes.rb with the output of
|
45
|
+
Also, if you pass the -r option, it'll annotate routes.rb with the output of
|
46
|
+
`rake routes`.
|
47
|
+
|
41
48
|
|
42
|
-
==
|
49
|
+
== Install
|
43
50
|
|
44
51
|
Into Gemfile from rubygems.org:
|
45
52
|
|
@@ -49,7 +56,7 @@ Into Gemfile from Github:
|
|
49
56
|
|
50
57
|
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
|
51
58
|
|
52
|
-
Into environment gems
|
59
|
+
Into environment gems from rubygems.org:
|
53
60
|
|
54
61
|
gem install annotate
|
55
62
|
|
@@ -60,50 +67,111 @@ Into environment gems from Github checkout:
|
|
60
67
|
rake build
|
61
68
|
gem install pkg/annotate-*.gem
|
62
69
|
|
63
|
-
|
70
|
+
|
71
|
+
== Usage
|
64
72
|
|
65
73
|
(If you used the Gemfile install, prefix the below commands with `bundle exec`.)
|
66
74
|
|
67
|
-
|
75
|
+
=== Usage in Rails
|
68
76
|
|
69
|
-
|
70
|
-
annotate
|
77
|
+
To annotate all your models, tests, fixtures, and factories:
|
71
78
|
|
72
|
-
|
79
|
+
cd /path/to/app
|
80
|
+
annotate
|
73
81
|
|
74
|
-
|
82
|
+
To annotate just your models, tests, and factories:
|
83
|
+
|
84
|
+
annotate --exclude fixtures
|
75
85
|
|
76
86
|
To annotate just your models:
|
77
87
|
|
78
|
-
|
88
|
+
annotate --exclude tests,fixtures,factories
|
79
89
|
|
80
90
|
To annotate routes.rb:
|
81
91
|
|
82
|
-
|
92
|
+
annotate --routes
|
93
|
+
|
94
|
+
To remove model/test/fixture/factory annotations:
|
95
|
+
|
96
|
+
annotate --delete
|
97
|
+
|
98
|
+
To remove routes.rb annotations:
|
99
|
+
|
100
|
+
annotate --routes --delete
|
101
|
+
|
83
102
|
|
84
|
-
|
103
|
+
== Configuration
|
85
104
|
|
86
|
-
annotate -d
|
87
105
|
|
88
|
-
|
89
|
-
annotate_models to your Rails project's Gemfile, and run this:
|
106
|
+
=== Usage Outside of Rails
|
90
107
|
|
91
|
-
|
108
|
+
Everything above applies, except that --routes is not meaningful, and you will
|
109
|
+
probably need to explicitly set one or more `--require` option(s), and/or one
|
110
|
+
or more `--model-dir` options to inform annotate about the structure of your
|
111
|
+
project and help it bootstrap and load the relevant code.
|
92
112
|
|
93
|
-
|
94
|
-
|
95
|
-
|
113
|
+
|
114
|
+
|
115
|
+
== Configuration
|
96
116
|
|
97
117
|
If you want to always skip annotations on a particular model, add this string
|
98
118
|
anywhere in the file:
|
99
119
|
|
100
|
-
|
120
|
+
# -*- SkipSchemaAnnotations
|
121
|
+
|
122
|
+
To generate a configuration file (in the form of a `.rake` file), to set
|
123
|
+
default options:
|
124
|
+
|
125
|
+
rails g annotate:install
|
126
|
+
|
127
|
+
Edit this file to control things like output format, where annotations are
|
128
|
+
added (top or bottom of file), and in which artifacts.
|
129
|
+
|
130
|
+
|
131
|
+
=== Configuration in Rails
|
132
|
+
|
133
|
+
To generate a configuration file (in the form of a `.rake` file), to set
|
134
|
+
default options:
|
135
|
+
|
136
|
+
rails g annotate:install
|
101
137
|
|
102
|
-
|
138
|
+
Edit this file to control things like output format, where annotations are
|
139
|
+
added (top or bottom of file), and in which artifacts.
|
140
|
+
== Rails Integration
|
141
|
+
|
142
|
+
By default, once you've generated a configuration file, annotate will be
|
143
|
+
executed whenever you run `rake db:migrate` (but only in development mode).
|
144
|
+
If you want to disable this behavior permanently, edit the `.rake` file and
|
145
|
+
change:
|
146
|
+
|
147
|
+
'skip_on_db_migrate' => "false",
|
148
|
+
|
149
|
+
To:
|
150
|
+
|
151
|
+
'skip_on_db_migrate' => "try",
|
152
|
+
|
153
|
+
If you want to run `rake db:migrate` as a one-off without running annotate,
|
154
|
+
you can do so with a simple environment variable, instead of editing the
|
155
|
+
`.rake` file:
|
156
|
+
|
157
|
+
skip_on_db_migrate=1 rake db:migrate
|
158
|
+
|
159
|
+
|
160
|
+
== Options
|
103
161
|
|
104
162
|
Usage: annotate [options] [model_file]*
|
105
|
-
-d, --delete Remove annotations from all model files
|
106
|
-
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model file
|
163
|
+
-d, --delete Remove annotations from all model files or the routes.rb file
|
164
|
+
-p, --position [before|after] Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/routes file(s)
|
165
|
+
--pc, --position-in-class [before|after]
|
166
|
+
Place the annotations at the top (before) or the bottom (after) of the model file
|
167
|
+
--pf, --position-in-factory [before|after]
|
168
|
+
Place the annotations at the top (before) or the bottom (after) of any factory files
|
169
|
+
--px, --position-in-fixture [before|after]
|
170
|
+
Place the annotations at the top (before) or the bottom (after) of any fixture files
|
171
|
+
--pt, --position-in-test [before|after]
|
172
|
+
Place the annotations at the top (before) or the bottom (after) of any test files
|
173
|
+
--pr, --position-in-routes [before|after]
|
174
|
+
Place the annotations at the top (before) or the bottom (after) of the routes.rb file
|
107
175
|
-r, --routes Annotate routes.rb with the output of 'rake routes'
|
108
176
|
-v, --version Show the current version of this gem
|
109
177
|
-m, --show-migration Include the migration version number in the annotation
|
@@ -112,31 +180,51 @@ anywhere in the file:
|
|
112
180
|
--model-dir dir Annotate model files stored in dir rather than app/models
|
113
181
|
--ignore-model-subdirects Ignore subdirectories of the models directory
|
114
182
|
--sort Sort columns alphabetically, rather than in creation order
|
115
|
-
-R, --require path Additional
|
116
|
-
-e
|
183
|
+
-R, --require path Additional file to require before loading models, may be used multiple times
|
184
|
+
-e [tests,fixtures,factories], Do not annotate fixtures, test files, and/or factories
|
185
|
+
--exclude
|
117
186
|
-f [bare|rdoc|markdown], Render Schema Infomation as plain/RDoc/Markdown
|
118
187
|
--format
|
119
188
|
--force Force new annotations even if there are no changes.
|
120
189
|
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
|
121
190
|
|
122
191
|
|
123
|
-
==
|
192
|
+
== Sorting
|
124
193
|
|
125
|
-
By default, columns will be sorted in database order (i.e. the order in which
|
194
|
+
By default, columns will be sorted in database order (i.e. the order in which
|
195
|
+
migrations were run).
|
126
196
|
|
127
197
|
If you prefer to sort alphabetically so that the results of
|
128
|
-
annotation are consistent regardless of what order migrations are executed in,
|
198
|
+
annotation are consistent regardless of what order migrations are executed in,
|
199
|
+
use --sort.
|
200
|
+
|
201
|
+
|
202
|
+
== Markdown
|
203
|
+
|
204
|
+
The format produced is actually MultiMarkdown, making use of the syntax
|
205
|
+
extension for tables. It's recommended you use `kramdown` as your parser if
|
206
|
+
you want to use this format. If you're using `yard` to generate documentation,
|
207
|
+
specify a format of markdown with `kramdown` as the provider by adding this to
|
208
|
+
your `.yardopts` file:
|
209
|
+
|
210
|
+
--markup markdown
|
211
|
+
--markup-provider kramdown
|
212
|
+
|
213
|
+
Be sure to add this to your `Gemfile` as well:
|
214
|
+
|
215
|
+
gem 'kramdown', :groups => [:development], :require => false
|
216
|
+
|
129
217
|
|
130
218
|
== WARNING
|
131
219
|
|
132
|
-
Note that this code will blow away the initial/final comment
|
133
|
-
|
134
|
-
|
135
|
-
to an automatically created comment block.
|
220
|
+
Note that this code will blow away the initial/final comment block in your
|
221
|
+
models if it looks like it was previously added by this gem, so you don't want
|
222
|
+
to add additional text to an automatically created comment block.
|
136
223
|
|
137
224
|
BACK UP YOUR MODELS BEFORE USING THIS TOOL!
|
138
225
|
|
139
|
-
|
226
|
+
|
227
|
+
== Links
|
140
228
|
|
141
229
|
- Factory Girl: http://github.com/thoughtbot/factory_girl
|
142
230
|
- Object Daddy: http://github.com/flogic/object_daddy
|
@@ -145,11 +233,13 @@ BACK UP YOUR MODELS BEFORE USING THIS TOOL!
|
|
145
233
|
- SpatialAdapter: http://github.com/pdeffendol/spatial_adapter
|
146
234
|
- PostgisAdapter: http://github.com/nofxx/postgis_adapter
|
147
235
|
|
148
|
-
|
236
|
+
|
237
|
+
== License
|
149
238
|
|
150
239
|
Released under the same license as Ruby. No Support. No Warranty.
|
151
240
|
|
152
|
-
|
241
|
+
|
242
|
+
== Authors
|
153
243
|
|
154
244
|
- Original code by: Dave Thomas -- Pragmatic Programmers, LLC <http://agilewebdevelopment.com/plugins/annotate_models>
|
155
245
|
- Overhauled by: Alex Chaffee <http://alexch.github.com> alex@stinky.com
|
@@ -181,4 +271,4 @@ With help from:
|
|
181
271
|
- Dmitry Lihachev
|
182
272
|
- qichunren
|
183
273
|
|
184
|
-
and many others that I may have
|
274
|
+
and many others that I may have forgotten to add.
|
data/TODO.rdoc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
== TODO
|
2
|
+
|
3
|
+
- clean up history
|
4
|
+
- change default position back to "top" for all annotations
|
5
|
+
- add "top" and "bottom" as synonyms for "before" and "after"
|
6
|
+
- change 'exclude' to 'only' (double negatives are not unconfusing)
|
7
|
+
|
8
|
+
== TODO (proposed)
|
9
|
+
|
10
|
+
- push two identical gems, named 'annotate' and 'annotate_models'
|
11
|
+
- supply two binaries, named 'annotate' and 'annotate_models', since there's already a unix tool named 'annotate'
|
12
|
+
- test EVERYTHING
|
data/annotate.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# This file is auto-generated!
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY!
|
3
|
+
# Instead, edit the Rakefile and run 'rake gems:gemspec'.# -*- encoding: utf-8 -*-
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "annotate"
|
7
|
+
s.version = "2.6.0.beta2"
|
8
|
+
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini", "Turadg Aleahmad", "Jon Frisby"]
|
11
|
+
s.date = "2013-06-21"
|
12
|
+
s.description = "Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema."
|
13
|
+
s.email = ["alex@stinky.com", "ctran@pragmaquest.com", "x@nofxx.com", "turadg@aleahmad.net", "jon@cloudability.com"]
|
14
|
+
s.executables = ["annotate"]
|
15
|
+
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "TODO.rdoc"]
|
16
|
+
s.files = ["CHANGELOG.rdoc", "README.rdoc", "TODO.rdoc", "annotate.gemspec", "bin/annotate", "lib/annotate.rb", "lib/annotate/active_record_patch.rb", "lib/annotate/annotate_models.rb", "lib/annotate/annotate_routes.rb", "lib/annotate/tasks.rb", "lib/annotate/version.rb", "lib/generators/annotate/USAGE", "lib/generators/annotate/install_generator.rb", "lib/generators/annotate/templates/auto_annotate_models.rake", "lib/tasks/annotate_models.rake", "lib/tasks/annotate_routes.rake", "tasks/migrate.rake"]
|
17
|
+
s.homepage = "http://github.com/ctran/annotate_models"
|
18
|
+
s.licenses = ["Ruby"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = "annotate"
|
21
|
+
s.rubygems_version = "2.0.3"
|
22
|
+
s.summary = "Annotates Rails Models, routes, fixtures, and others based on the database schema."
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
s.specification_version = 4
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<rake>, [">= 0.8.7"])
|
29
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
32
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
36
|
+
s.add_dependency(%q<activerecord>, [">= 2.3.0"])
|
37
|
+
end
|
38
|
+
end
|
data/bin/annotate
CHANGED
@@ -1,34 +1,78 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
3
|
-
require 'rake/dsl_definition'
|
4
|
-
require 'rake'
|
2
|
+
require 'rubygems'
|
5
3
|
begin
|
6
|
-
require
|
7
|
-
|
8
|
-
|
9
|
-
$:<< "#{here}/../lib"
|
10
|
-
require "annotate"
|
4
|
+
require 'bundler'
|
5
|
+
Bundler.setup
|
6
|
+
rescue Exception => e
|
11
7
|
end
|
12
8
|
|
13
|
-
|
9
|
+
here = File.expand_path(File.dirname __FILE__)
|
10
|
+
$:<< "#{here}/../lib"
|
14
11
|
|
12
|
+
require 'optparse'
|
13
|
+
require 'annotate'
|
14
|
+
Annotate.bootstrap_rake
|
15
|
+
|
16
|
+
target = {
|
17
|
+
:klass => AnnotateModels,
|
18
|
+
:task => :do_annotations,
|
19
|
+
}
|
20
|
+
has_set_position = {}
|
15
21
|
OptionParser.new do |opts|
|
16
22
|
opts.banner = "Usage: annotate [options] [model_file]*"
|
17
23
|
|
18
24
|
opts.on('-d', '--delete',
|
19
|
-
"Remove annotations from all model files") do
|
20
|
-
|
25
|
+
"Remove annotations from all model files or the routes.rb file") do
|
26
|
+
|
27
|
+
target[:task] = :remove_annotations
|
21
28
|
end
|
22
29
|
|
23
|
-
ENV['position'] = 'before' # hack: make sure default position is "before"
|
24
30
|
opts.on('-p', '--position [before|after]', ['before', 'after'],
|
25
|
-
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
|
31
|
+
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/routes file(s)") do |p|
|
26
32
|
ENV['position'] = p
|
33
|
+
[
|
34
|
+
'position_in_class','position_in_factory','position_in_fixture','position_in_test', 'position_in_routes'
|
35
|
+
].each do |key|
|
36
|
+
ENV[key] = p unless(has_set_position[key])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on('--pc', '--position-in-class [before|after]', ['before', 'after'],
|
41
|
+
"Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
|
42
|
+
ENV['position_in_class'] = p
|
43
|
+
has_set_position['position_in_class'] = true
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('--pf', '--position-in-factory [before|after]', ['before', 'after'],
|
47
|
+
"Place the annotations at the top (before) or the bottom (after) of any factory files") do |p|
|
48
|
+
ENV['position_in_factory'] = p
|
49
|
+
has_set_position['position_in_factory'] = true
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('--px', '--position-in-fixture [before|after]', ['before', 'after'],
|
53
|
+
"Place the annotations at the top (before) or the bottom (after) of any fixture files") do |p|
|
54
|
+
ENV['position_in_fixture'] = p
|
55
|
+
has_set_position['position_in_fixture'] = true
|
56
|
+
end
|
57
|
+
|
58
|
+
opts.on('--pt', '--position-in-test [before|after]', ['before', 'after'],
|
59
|
+
"Place the annotations at the top (before) or the bottom (after) of any test files") do |p|
|
60
|
+
ENV['position_in_test'] = p
|
61
|
+
has_set_position['position_in_test'] = true
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on('--pr', '--position-in-routes [before|after]', ['before', 'after'],
|
65
|
+
"Place the annotations at the top (before) or the bottom (after) of the routes.rb file") do |p|
|
66
|
+
ENV['position_in_test'] = p
|
67
|
+
has_set_position['position_in_routes'] = true
|
27
68
|
end
|
28
69
|
|
29
70
|
opts.on('-r', '--routes',
|
30
71
|
"Annotate routes.rb with the output of 'rake routes'") do
|
31
|
-
|
72
|
+
target = {
|
73
|
+
:klass => AnnotateRoutes,
|
74
|
+
:task => :do_annotations
|
75
|
+
}
|
32
76
|
end
|
33
77
|
|
34
78
|
opts.on('-v', '--version',
|
@@ -67,15 +111,15 @@ OptionParser.new do |opts|
|
|
67
111
|
end
|
68
112
|
|
69
113
|
opts.on('-R', '--require path',
|
70
|
-
"Additional
|
71
|
-
if ENV['require']
|
114
|
+
"Additional file to require before loading models, may be used multiple times") do |path|
|
115
|
+
if !ENV['require'].blank?
|
72
116
|
ENV['require'] = ENV['require'] + ",#{path}"
|
73
117
|
else
|
74
118
|
ENV['require'] = path
|
75
119
|
end
|
76
|
-
end
|
120
|
+
end
|
77
121
|
|
78
|
-
opts.on('-e', '--exclude [tests,fixtures]',
|
122
|
+
opts.on('-e', '--exclude [tests,fixtures,factories]', ['tests','fixtures','factories'], "Do not annotate fixtures, test files, and/or factories") do |exclusions|
|
79
123
|
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
|
80
124
|
end
|
81
125
|
|
@@ -90,13 +134,9 @@ OptionParser.new do |opts|
|
|
90
134
|
opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|
|
91
135
|
ENV['trace'] = 'yes'
|
92
136
|
end
|
93
|
-
|
94
|
-
|
95
137
|
end.parse!
|
96
138
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
STDERR.puts "Can't find Rakefile. Are we in a Rails folder?"
|
102
|
-
end
|
139
|
+
|
140
|
+
options=Annotate.setup_options({ :is_rake => !ENV['is_rake'].blank? })
|
141
|
+
Annotate.eager_load(options)
|
142
|
+
target[:klass].send(target[:task], options)
|