annotate 3.0.2 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{AUTHORS.rdoc → AUTHORS.md} +2 -2
- data/CHANGELOG.md +326 -0
- data/{README.rdoc → README.md} +139 -105
- data/RELEASE.md +19 -0
- data/annotate.gemspec +11 -28
- data/bin/annotate +3 -3
- data/lib/annotate/annotate_models/file_patterns.rb +127 -0
- data/lib/annotate/annotate_models.rb +156 -181
- 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 +44 -177
- data/lib/annotate/constants.rb +33 -0
- data/lib/annotate/helpers.rb +30 -0
- data/lib/annotate/parser.rb +127 -75
- data/lib/annotate/version.rb +1 -1
- data/lib/annotate.rb +21 -80
- data/lib/generators/annotate/templates/auto_annotate_models.rake +3 -1
- data/lib/tasks/annotate_models.rake +36 -35
- data/lib/tasks/annotate_models_migrate.rake +17 -4
- data/lib/tasks/annotate_routes.rake +12 -6
- data/potato.md +41 -0
- metadata +23 -18
- data/CHANGELOG.rdoc +0 -238
- data/TODO.rdoc +0 -11
data/{README.rdoc → README.md}
RENAMED
@@ -1,14 +1,14 @@
|
|
1
|
-
|
1
|
+
## Annotate (aka AnnotateModels)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/annotate.svg)](http://badge.fury.io/rb/annotate)
|
4
|
+
[![Downloads count](https://img.shields.io/gem/dt/annotate.svg?style=flat)](https://rubygems.org/gems/annotate)
|
5
|
+
[![Build status](https://travis-ci.org/ctran/annotate_models.svg?branch=develop)](https://travis-ci.org/ctran/annotate_models)
|
6
|
+
[![CI Status](https://github.com/ctran/annotate_models/workflows/CI/badge.svg)](https://github.com/ctran/annotate_models/actions?workflow=CI)
|
7
|
+
[![Coveralls](https://coveralls.io/repos/ctran/annotate_models/badge.svg?branch=develop)](https://coveralls.io/r/ctran/annotate_models?branch=develop)
|
8
|
+
[![Maintenability](https://codeclimate.com/github/ctran/annotate_models/badges/gpa.svg)](https://codeclimate.com/github/ctran/annotate_models)
|
9
|
+
[![Inline docs](http://inch-ci.org/github/ctran/annotate_models.svg?branch=develop)](http://inch-ci.org/github/ctran/annotate_models)
|
9
10
|
|
10
|
-
Add a comment summarizing the current schema to the top or bottom of each of
|
11
|
-
your...
|
11
|
+
Add a comment summarizing the current schema to the top or bottom of each of your...
|
12
12
|
|
13
13
|
- ActiveRecord models
|
14
14
|
- Fixture files
|
@@ -16,53 +16,85 @@ your...
|
|
16
16
|
- Object Daddy exemplars
|
17
17
|
- Machinist blueprints
|
18
18
|
- Fabrication fabricators
|
19
|
-
- Thoughtbot's factory_bot factories, i.e. the (spec|test)/factories/<model>_factory.rb files
|
20
|
-
- 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
|
+
|
21
22
|
|
22
23
|
The schema comment looks like this:
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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`.
|
55
|
+
|
56
|
+
|
57
|
+
## Upgrading to 3.X and annotate models not working?
|
34
58
|
|
35
|
-
|
36
|
-
|
37
|
-
|
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).
|
38
63
|
|
39
|
-
|
40
|
-
+SpatialAdapter+, +PostgisAdapter+ or +PostGISAdapter+:
|
64
|
+
There are a few ways of fixing this:
|
41
65
|
|
42
|
-
|
43
|
-
#
|
44
|
-
# Table name: trips
|
45
|
-
#
|
46
|
-
# local :geometry point, 4326
|
47
|
-
# path :geometry line_string, 4326
|
66
|
+
- If using CLI explicitly pass in models flag using `--models`
|
48
67
|
|
49
|
-
|
50
|
-
<code>rake routes</code>.
|
68
|
+
OR
|
51
69
|
|
70
|
+
a) Running `rails g annotate:install` will overwrite your defaults with the annotating `models` option set to `'true'`.
|
52
71
|
|
53
|
-
|
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
|
54
82
|
|
55
83
|
Into Gemfile from rubygems.org:
|
56
84
|
|
57
|
-
|
58
|
-
|
59
|
-
|
85
|
+
```ruby
|
86
|
+
group :development do
|
87
|
+
gem 'annotate'
|
88
|
+
end
|
89
|
+
```
|
60
90
|
|
61
91
|
Into Gemfile from Github:
|
62
92
|
|
63
|
-
|
64
|
-
|
65
|
-
|
93
|
+
```ruby
|
94
|
+
group :development do
|
95
|
+
gem 'annotate', git: 'https://github.com/ctran/annotate_models.git'
|
96
|
+
end
|
97
|
+
```
|
66
98
|
|
67
99
|
Into environment gems from rubygems.org:
|
68
100
|
|
@@ -72,15 +104,14 @@ Into environment gems from Github checkout:
|
|
72
104
|
|
73
105
|
git clone https://github.com/ctran/annotate_models.git annotate_models
|
74
106
|
cd annotate_models
|
75
|
-
rake
|
76
|
-
gem install
|
77
|
-
|
107
|
+
rake gem
|
108
|
+
gem install dist/annotate-*.gem
|
78
109
|
|
79
|
-
|
110
|
+
## Usage
|
80
111
|
|
81
|
-
(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`.)
|
82
113
|
|
83
|
-
|
114
|
+
### Usage in Rails
|
84
115
|
|
85
116
|
To annotate all your models, tests, fixtures, and factories:
|
86
117
|
|
@@ -107,26 +138,28 @@ To remove routes.rb annotations:
|
|
107
138
|
|
108
139
|
annotate --routes --delete
|
109
140
|
|
110
|
-
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`.
|
111
144
|
|
112
|
-
|
145
|
+
See the [configuration in Rails](#configuration-in-rails) section for more info.
|
113
146
|
|
114
|
-
|
115
|
-
probably need to explicitly set one or more +--require+ option(s), and/or one
|
116
|
-
or more +--model-dir+ options to inform annotate about the structure of your
|
117
|
-
project and help it bootstrap and load the relevant code.
|
147
|
+
### Usage Outside of Rails
|
118
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.
|
119
152
|
|
120
|
-
|
153
|
+
## Configuration
|
121
154
|
|
122
155
|
If you want to always skip annotations on a particular model, add this string
|
123
156
|
anywhere in the file:
|
124
157
|
|
125
158
|
# -*- SkipSchemaAnnotations
|
126
159
|
|
127
|
-
|
160
|
+
### Configuration in Rails
|
128
161
|
|
129
|
-
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
|
130
163
|
default options:
|
131
164
|
|
132
165
|
rails g annotate:install
|
@@ -134,7 +167,7 @@ default options:
|
|
134
167
|
Edit this file to control things like output format, where annotations are
|
135
168
|
added (top or bottom of file), and in which artifacts.
|
136
169
|
|
137
|
-
The generated rakefile
|
170
|
+
The generated rakefile `lib/tasks/auto_annotate_models.rake` also contains
|
138
171
|
`Annotate.load_tasks`. This adds a few rake tasks which duplicate command-line
|
139
172
|
functionality:
|
140
173
|
|
@@ -143,24 +176,27 @@ functionality:
|
|
143
176
|
rake remove_annotation # Remove schema information from model and fixture files
|
144
177
|
|
145
178
|
By default, once you've generated a configuration file, annotate will be
|
146
|
-
executed whenever you run
|
147
|
-
If you want to disable this behavior permanently,
|
148
|
-
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:
|
149
182
|
|
183
|
+
```ruby
|
150
184
|
'skip_on_db_migrate' => 'false',
|
185
|
+
```
|
151
186
|
|
152
187
|
To:
|
153
188
|
|
189
|
+
```ruby
|
154
190
|
'skip_on_db_migrate' => 'true',
|
191
|
+
```
|
155
192
|
|
156
|
-
If you want to run
|
193
|
+
If you want to run `rake db:migrate` as a one-off without running annotate,
|
157
194
|
you can do so with a simple environment variable, instead of editing the
|
158
|
-
|
195
|
+
`.rake` file:
|
159
196
|
|
160
197
|
ANNOTATE_SKIP_ON_DB_MIGRATE=1 rake db:migrate
|
161
198
|
|
162
|
-
|
163
|
-
== Options
|
199
|
+
## Options
|
164
200
|
|
165
201
|
Usage: annotate [options] [model_file]*
|
166
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`)
|
@@ -201,7 +237,7 @@ you can do so with a simple environment variable, instead of editing the
|
|
201
237
|
-R, --require path Additional file to require before loading models, may be used multiple times
|
202
238
|
-e [tests,fixtures,factories,serializers],
|
203
239
|
--exclude Do not annotate fixtures, test files, factories, and/or serializers
|
204
|
-
-f [bare|rdoc|markdown],
|
240
|
+
-f [bare|rdoc|yard|markdown], Render Schema Infomation as plain/RDoc/YARD/Markdown
|
205
241
|
--format
|
206
242
|
--force Force new annotations even if there are no changes.
|
207
243
|
--frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files.
|
@@ -216,82 +252,80 @@ you can do so with a simple environment variable, instead of editing the
|
|
216
252
|
--ignore-unknown-models don't display warnings for bad model files
|
217
253
|
--with-comment include database comments in model annotations
|
218
254
|
|
219
|
-
|
255
|
+
### Option: `additional_file_patterns`
|
220
256
|
|
221
|
-
CLI:
|
222
|
-
Ruby:
|
257
|
+
CLI: `--additional-file-patterns`<br>
|
258
|
+
Ruby: `:additional_file_patterns`
|
223
259
|
|
224
|
-
Provide additional paths for the gem to annotate. These paths can include
|
225
|
-
It is recommended to use absolute paths. Here are some examples:
|
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:
|
226
262
|
|
263
|
+
* `/app/lib/decorates/%MODEL_NAME%/*.rb`
|
264
|
+
* `/app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb`
|
265
|
+
* `/app/lib/forms/%TABLE_NAME%/*.rb`
|
227
266
|
|
228
|
-
- <code>/app/lib/decorates/%MODEL_NAME%/*.rb</code>
|
229
|
-
- <code>/app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb</code>
|
230
|
-
- <code>/app/lib/forms/%TABLE_NAME%/*.rb</code>
|
231
267
|
|
232
|
-
The appropriate model will be inferred using the
|
233
|
-
It works with existing filename resolutions (options for which
|
234
|
-
|
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`).
|
235
271
|
|
236
272
|
When using in a Rails config, you can use the following:
|
237
273
|
|
238
|
-
|
274
|
+
`File.join(Rails.application.root,
|
275
|
+
'app/lib/forms/%PLURALIZED_MODEL_NAME%/***/**.rb')`
|
239
276
|
|
240
|
-
|
277
|
+
## Sorting
|
241
278
|
|
242
279
|
By default, columns will be sorted in database order (i.e. the order in which
|
243
280
|
migrations were run).
|
244
281
|
|
245
|
-
If you prefer to sort alphabetically so that the results of
|
246
|
-
|
247
|
-
use +--sort+.
|
248
|
-
|
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`.
|
249
284
|
|
250
|
-
|
285
|
+
## Markdown
|
251
286
|
|
252
287
|
The format produced is actually MultiMarkdown, making use of the syntax
|
253
|
-
extension for tables. It's recommended you use
|
254
|
-
you want to use this format. If you're using
|
255
|
-
specify a format of markdown with
|
256
|
-
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:
|
257
292
|
|
258
293
|
--markup markdown
|
259
294
|
--markup-provider kramdown
|
260
295
|
|
261
|
-
Be sure to add this to your
|
262
|
-
|
263
|
-
gem 'kramdown', :groups => [:development], :require => false
|
296
|
+
Be sure to add this to your `Gemfile` as well:
|
264
297
|
|
298
|
+
gem 'kramdown', groups => [:development], require => false
|
265
299
|
|
266
|
-
|
300
|
+
## WARNING
|
267
301
|
|
268
|
-
|
302
|
+
**Don't add text after an automatically-created comment block.** This tool
|
269
303
|
will blow away the initial/final comment block in your models if it looks like
|
270
304
|
it was previously added by this gem.
|
271
305
|
|
272
|
-
Be sure to check the changes that this tool makes! If you are using Git,
|
273
|
-
|
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`:
|
274
308
|
|
275
309
|
$ git status
|
276
310
|
|
277
311
|
If you are not using a VCS (like Git, Subversion or similar), please tread
|
278
312
|
extra carefully, and consider using one.
|
279
313
|
|
280
|
-
|
314
|
+
## Links
|
281
315
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
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
|
289
323
|
|
290
324
|
|
291
|
-
|
325
|
+
## License
|
292
326
|
|
293
327
|
Released under the same license as Ruby. No Support. No Warranty.
|
294
328
|
|
295
|
-
|
329
|
+
## Authors
|
296
330
|
|
297
|
-
|
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,43 +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/constants.rb',
|
30
|
-
'lib/annotate/parser.rb',
|
31
|
-
'lib/annotate/tasks.rb',
|
32
|
-
'lib/annotate/version.rb',
|
33
|
-
'lib/generators/annotate/USAGE',
|
34
|
-
'lib/generators/annotate/install_generator.rb',
|
35
|
-
'lib/generators/annotate/templates/auto_annotate_models.rake',
|
36
|
-
'lib/tasks/annotate_models.rake',
|
37
|
-
'lib/tasks/annotate_routes.rake',
|
38
|
-
'lib/tasks/annotate_models_migrate.rake'
|
39
|
-
]
|
40
|
-
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'
|
41
19
|
s.licenses = ['Ruby']
|
42
20
|
s.require_paths = ['lib']
|
43
21
|
s.rubygems_version = '2.1.11'
|
44
22
|
s.summary = 'Annotates Rails Models, routes, fixtures, and others based on the database schema.'
|
45
23
|
|
46
24
|
s.specification_version = 4 if s.respond_to? :specification_version
|
47
|
-
s.add_runtime_dependency(%q<rake>,
|
48
|
-
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
|
+
}
|
49
32
|
end
|
data/bin/annotate
CHANGED
@@ -26,7 +26,7 @@ exit if options_result[:exit]
|
|
26
26
|
options = Annotate.setup_options(
|
27
27
|
is_rake: ENV['is_rake'] && !ENV['is_rake'].empty?
|
28
28
|
)
|
29
|
-
Annotate.eager_load(options) if Annotate.include_models?
|
29
|
+
Annotate.eager_load(options) if Annotate::Helpers.include_models?
|
30
30
|
|
31
|
-
AnnotateModels.send(options_result[:target_action], options) if Annotate.include_models?
|
32
|
-
AnnotateRoutes.send(options_result[:target_action], options) if Annotate.include_routes?
|
31
|
+
AnnotateModels.send(options_result[:target_action], options) if Annotate::Helpers.include_models?
|
32
|
+
AnnotateRoutes.send(options_result[:target_action], options) if Annotate::Helpers.include_routes?
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module AnnotateModels
|
2
|
+
# This module provides module method to get file paths.
|
3
|
+
module FilePatterns
|
4
|
+
# Controller files
|
5
|
+
CONTROLLER_DIR = File.join('app', 'controllers')
|
6
|
+
|
7
|
+
# Active admin registry files
|
8
|
+
ACTIVEADMIN_DIR = File.join('app', 'admin')
|
9
|
+
|
10
|
+
# Helper files
|
11
|
+
HELPER_DIR = File.join('app', 'helpers')
|
12
|
+
|
13
|
+
# File.join for windows reverse bar compat?
|
14
|
+
# I dont use windows, can`t test
|
15
|
+
UNIT_TEST_DIR = File.join('test', 'unit')
|
16
|
+
MODEL_TEST_DIR = File.join('test', 'models') # since rails 4.0
|
17
|
+
SPEC_MODEL_DIR = File.join('spec', 'models')
|
18
|
+
|
19
|
+
FIXTURE_TEST_DIR = File.join('test', 'fixtures')
|
20
|
+
FIXTURE_SPEC_DIR = File.join('spec', 'fixtures')
|
21
|
+
|
22
|
+
# Other test files
|
23
|
+
CONTROLLER_TEST_DIR = File.join('test', 'controllers')
|
24
|
+
CONTROLLER_SPEC_DIR = File.join('spec', 'controllers')
|
25
|
+
REQUEST_SPEC_DIR = File.join('spec', 'requests')
|
26
|
+
ROUTING_SPEC_DIR = File.join('spec', 'routing')
|
27
|
+
|
28
|
+
# Object Daddy http://github.com/flogic/object_daddy/tree/master
|
29
|
+
EXEMPLARS_TEST_DIR = File.join('test', 'exemplars')
|
30
|
+
EXEMPLARS_SPEC_DIR = File.join('spec', 'exemplars')
|
31
|
+
|
32
|
+
# Machinist http://github.com/notahat/machinist
|
33
|
+
BLUEPRINTS_TEST_DIR = File.join('test', 'blueprints')
|
34
|
+
BLUEPRINTS_SPEC_DIR = File.join('spec', 'blueprints')
|
35
|
+
|
36
|
+
# Factory Bot https://github.com/thoughtbot/factory_bot
|
37
|
+
FACTORY_BOT_TEST_DIR = File.join('test', 'factories')
|
38
|
+
FACTORY_BOT_SPEC_DIR = File.join('spec', 'factories')
|
39
|
+
|
40
|
+
# Fabrication https://github.com/paulelliott/fabrication.git
|
41
|
+
FABRICATORS_TEST_DIR = File.join('test', 'fabricators')
|
42
|
+
FABRICATORS_SPEC_DIR = File.join('spec', 'fabricators')
|
43
|
+
|
44
|
+
# Serializers https://github.com/rails-api/active_model_serializers
|
45
|
+
SERIALIZERS_DIR = File.join('app', 'serializers')
|
46
|
+
SERIALIZERS_TEST_DIR = File.join('test', 'serializers')
|
47
|
+
SERIALIZERS_SPEC_DIR = File.join('spec', 'serializers')
|
48
|
+
|
49
|
+
class << self
|
50
|
+
def generate(root_directory, pattern_type, options)
|
51
|
+
case pattern_type
|
52
|
+
when 'test' then test_files(root_directory)
|
53
|
+
when 'fixture' then fixture_files(root_directory)
|
54
|
+
when 'scaffold' then scaffold_files(root_directory)
|
55
|
+
when 'factory' then factory_files(root_directory)
|
56
|
+
when 'serializer' then serialize_files(root_directory)
|
57
|
+
when 'additional_file_patterns'
|
58
|
+
[options[:additional_file_patterns] || []].flatten
|
59
|
+
when 'controller'
|
60
|
+
[File.join(root_directory, CONTROLLER_DIR, '%PLURALIZED_MODEL_NAME%_controller.rb')]
|
61
|
+
when 'admin'
|
62
|
+
[
|
63
|
+
File.join(root_directory, ACTIVEADMIN_DIR, '%MODEL_NAME%.rb'),
|
64
|
+
File.join(root_directory, ACTIVEADMIN_DIR, '%PLURALIZED_MODEL_NAME%.rb')
|
65
|
+
]
|
66
|
+
when 'helper'
|
67
|
+
[File.join(root_directory, HELPER_DIR, '%PLURALIZED_MODEL_NAME%_helper.rb')]
|
68
|
+
else
|
69
|
+
[]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def test_files(root_directory)
|
76
|
+
[
|
77
|
+
File.join(root_directory, UNIT_TEST_DIR, '%MODEL_NAME%_test.rb'),
|
78
|
+
File.join(root_directory, MODEL_TEST_DIR, '%MODEL_NAME%_test.rb'),
|
79
|
+
File.join(root_directory, SPEC_MODEL_DIR, '%MODEL_NAME%_spec.rb')
|
80
|
+
]
|
81
|
+
end
|
82
|
+
|
83
|
+
def fixture_files(root_directory)
|
84
|
+
[
|
85
|
+
File.join(root_directory, FIXTURE_TEST_DIR, '%TABLE_NAME%.yml'),
|
86
|
+
File.join(root_directory, FIXTURE_SPEC_DIR, '%TABLE_NAME%.yml'),
|
87
|
+
File.join(root_directory, FIXTURE_TEST_DIR, '%PLURALIZED_MODEL_NAME%.yml'),
|
88
|
+
File.join(root_directory, FIXTURE_SPEC_DIR, '%PLURALIZED_MODEL_NAME%.yml')
|
89
|
+
]
|
90
|
+
end
|
91
|
+
|
92
|
+
def scaffold_files(root_directory)
|
93
|
+
[
|
94
|
+
File.join(root_directory, CONTROLLER_TEST_DIR, '%PLURALIZED_MODEL_NAME%_controller_test.rb'),
|
95
|
+
File.join(root_directory, CONTROLLER_SPEC_DIR, '%PLURALIZED_MODEL_NAME%_controller_spec.rb'),
|
96
|
+
File.join(root_directory, REQUEST_SPEC_DIR, '%PLURALIZED_MODEL_NAME%_spec.rb'),
|
97
|
+
File.join(root_directory, ROUTING_SPEC_DIR, '%PLURALIZED_MODEL_NAME%_routing_spec.rb')
|
98
|
+
]
|
99
|
+
end
|
100
|
+
|
101
|
+
def factory_files(root_directory)
|
102
|
+
[
|
103
|
+
File.join(root_directory, EXEMPLARS_TEST_DIR, '%MODEL_NAME%_exemplar.rb'),
|
104
|
+
File.join(root_directory, EXEMPLARS_SPEC_DIR, '%MODEL_NAME%_exemplar.rb'),
|
105
|
+
File.join(root_directory, BLUEPRINTS_TEST_DIR, '%MODEL_NAME%_blueprint.rb'),
|
106
|
+
File.join(root_directory, BLUEPRINTS_SPEC_DIR, '%MODEL_NAME%_blueprint.rb'),
|
107
|
+
File.join(root_directory, FACTORY_BOT_TEST_DIR, '%MODEL_NAME%_factory.rb'), # (old style)
|
108
|
+
File.join(root_directory, FACTORY_BOT_SPEC_DIR, '%MODEL_NAME%_factory.rb'), # (old style)
|
109
|
+
File.join(root_directory, FACTORY_BOT_TEST_DIR, '%TABLE_NAME%.rb'), # (new style)
|
110
|
+
File.join(root_directory, FACTORY_BOT_SPEC_DIR, '%TABLE_NAME%.rb'), # (new style)
|
111
|
+
File.join(root_directory, FACTORY_BOT_TEST_DIR, '%PLURALIZED_MODEL_NAME%.rb'), # (new style)
|
112
|
+
File.join(root_directory, FACTORY_BOT_SPEC_DIR, '%PLURALIZED_MODEL_NAME%.rb'), # (new style)
|
113
|
+
File.join(root_directory, FABRICATORS_TEST_DIR, '%MODEL_NAME%_fabricator.rb'),
|
114
|
+
File.join(root_directory, FABRICATORS_SPEC_DIR, '%MODEL_NAME%_fabricator.rb')
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
def serialize_files(root_directory)
|
119
|
+
[
|
120
|
+
File.join(root_directory, SERIALIZERS_DIR, '%MODEL_NAME%_serializer.rb'),
|
121
|
+
File.join(root_directory, SERIALIZERS_TEST_DIR, '%MODEL_NAME%_serializer_test.rb'),
|
122
|
+
File.join(root_directory, SERIALIZERS_SPEC_DIR, '%MODEL_NAME%_serializer_spec.rb')
|
123
|
+
]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|