annot8 1.0.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 +7 -0
- data/AUTHORS.md +34 -0
- data/CHANGELOG.md +341 -0
- data/LICENSE.txt +55 -0
- data/README.md +331 -0
- data/RELEASE.md +19 -0
- data/annot8.gemspec +32 -0
- data/bin/annotate +31 -0
- data/lib/annotate/active_record_patch.rb +11 -0
- data/lib/annotate/annotate_models/file_patterns.rb +129 -0
- data/lib/annotate/annotate_models.rb +1005 -0
- data/lib/annotate/annotate_routes/header_generator.rb +117 -0
- data/lib/annotate/annotate_routes/helpers.rb +71 -0
- data/lib/annotate/annotate_routes.rb +121 -0
- data/lib/annotate/constants.rb +30 -0
- data/lib/annotate/helpers.rb +33 -0
- data/lib/annotate/parser.rb +317 -0
- data/lib/annotate/tasks.rb +8 -0
- data/lib/annotate/version.rb +7 -0
- data/lib/annotate.rb +152 -0
- data/lib/generators/annotate/USAGE +4 -0
- data/lib/generators/annotate/install_generator.rb +17 -0
- data/lib/generators/annotate/templates/auto_annotate_models.rake +63 -0
- data/lib/tasks/annotate_models.rake +79 -0
- data/lib/tasks/annotate_models_migrate.rake +65 -0
- data/lib/tasks/annotate_routes.rake +34 -0
- data/potato.md +41 -0
- metadata +120 -0
data/README.md
ADDED
@@ -0,0 +1,331 @@
|
|
1
|
+
## Annotate (aka AnnotateModels)
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/annot8)
|
4
|
+
[](https://rubygems.org/gems/annot8)
|
5
|
+
[](https://github.com/chemica/annotate_models/actions?workflow=CI)
|
6
|
+
|
7
|
+
**This is a fork of the [annotate](https://github.com/ctran/annotate_models) gem, built for Rails 8 and Ruby 3.2.2+.**
|
8
|
+
|
9
|
+
Add a comment summarizing the current schema to the top or bottom of each of your...
|
10
|
+
|
11
|
+
- ActiveRecord models
|
12
|
+
- Fixture files
|
13
|
+
- Tests and Specs
|
14
|
+
- Object Daddy exemplars
|
15
|
+
- Machinist blueprints
|
16
|
+
- Fabrication fabricators
|
17
|
+
- Thoughtbot's factory_bot factories, i.e. the `(spec|test)/factories/<model>_factory.rb` files
|
18
|
+
- `routes.rb` file (for Rails projects)
|
19
|
+
|
20
|
+
|
21
|
+
The schema comment looks like this:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# == Schema Info
|
25
|
+
#
|
26
|
+
# Table name: line_items
|
27
|
+
#
|
28
|
+
# id :integer(11) not null, primary key
|
29
|
+
# quantity :integer(11) not null
|
30
|
+
# product_id :integer(11) not null
|
31
|
+
# unit_price :float
|
32
|
+
# order_id :integer(11)
|
33
|
+
#
|
34
|
+
|
35
|
+
class LineItem < ActiveRecord::Base
|
36
|
+
belongs_to :product
|
37
|
+
. . .
|
38
|
+
```
|
39
|
+
|
40
|
+
It also annotates geometrical columns, `geom` type and `srid`,
|
41
|
+
when using `SpatialAdapter`, `PostgisAdapter` or `PostGISAdapter`:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
# == Schema Info
|
45
|
+
#
|
46
|
+
# Table name: trips
|
47
|
+
#
|
48
|
+
# local :geometry point, 4326
|
49
|
+
# path :geometry line_string, 4326
|
50
|
+
```
|
51
|
+
|
52
|
+
Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake routes`.
|
53
|
+
|
54
|
+
|
55
|
+
## Upgrading to 3.X and annotate models not working?
|
56
|
+
|
57
|
+
In versions 2.7.X in the original annotate gem, it defaulted to annotating models if no arguments were passed in.
|
58
|
+
The annotate gem by default would not allow for routes and models to be annotated together.
|
59
|
+
A [change was added in #647](https://github.com/ctran/annotate_models/pull/647).
|
60
|
+
You [can read more here](https://github.com/ctran/annotate_models/issues/663).
|
61
|
+
|
62
|
+
There are a few ways of fixing this:
|
63
|
+
|
64
|
+
- If using CLI explicitly pass in models flag using `--models`
|
65
|
+
|
66
|
+
OR
|
67
|
+
|
68
|
+
a) Running `rails g annotate:install` will overwrite your defaults with the annotating `models` option set to `'true'`.
|
69
|
+
|
70
|
+
b) In `lib/tasks/auto_annotate_models.rake` add the `models` key-value option:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Annotate.set_defaults(
|
74
|
+
...
|
75
|
+
'models' => 'true',
|
76
|
+
...
|
77
|
+
```
|
78
|
+
|
79
|
+
## Install
|
80
|
+
|
81
|
+
Into Gemfile from rubygems.org:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
group :development do
|
85
|
+
gem "annot8"
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
Into Gemfile from Github:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
group :development do
|
93
|
+
gem "annot8", git: "https://github.com/chemica/annotate_models.git"
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
Into environment gems from rubygems.org:
|
98
|
+
|
99
|
+
gem install annot8
|
100
|
+
|
101
|
+
Into environment gems from Github checkout:
|
102
|
+
|
103
|
+
git clone https://github.com/chemica/annotate_models.git annot8
|
104
|
+
cd annot8
|
105
|
+
rake gem
|
106
|
+
gem install dist/annot8-*.gem
|
107
|
+
|
108
|
+
## Usage
|
109
|
+
|
110
|
+
(If you used the Gemfile install, prefix the below commands with `bundle exec`.)
|
111
|
+
|
112
|
+
### Usage in Rails
|
113
|
+
|
114
|
+
To annotate all your models, tests, fixtures, and factories:
|
115
|
+
|
116
|
+
cd /path/to/app
|
117
|
+
annotate
|
118
|
+
|
119
|
+
To annotate just your models, tests, and factories:
|
120
|
+
|
121
|
+
annotate --models --exclude fixtures
|
122
|
+
|
123
|
+
To annotate just your models:
|
124
|
+
|
125
|
+
annotate --models
|
126
|
+
|
127
|
+
To annotate routes.rb:
|
128
|
+
|
129
|
+
annotate --routes
|
130
|
+
|
131
|
+
To remove model/test/fixture/factory/serializer annotations:
|
132
|
+
|
133
|
+
annotate --delete
|
134
|
+
|
135
|
+
To remove routes.rb annotations:
|
136
|
+
|
137
|
+
annotate --routes --delete
|
138
|
+
|
139
|
+
To automatically annotate every time you run `db:migrate`,
|
140
|
+
either run `rails g annotate:install`
|
141
|
+
or add `Annotate.load_tasks` to your `Rakefile`.
|
142
|
+
|
143
|
+
See the [configuration in Rails](#configuration-in-rails) section for more info.
|
144
|
+
|
145
|
+
### Usage Outside of Rails
|
146
|
+
|
147
|
+
Everything above applies, except that `--routes` is not meaningful,
|
148
|
+
and you will probably need to explicitly set one or more `--require` option(s), and/or one or more `--model-dir` options
|
149
|
+
to inform `annotate` about the structure of your project and help it bootstrap and load the relevant code.
|
150
|
+
|
151
|
+
## Configuration
|
152
|
+
|
153
|
+
If you want to always skip annotations on a particular model, add this string
|
154
|
+
anywhere in the file:
|
155
|
+
|
156
|
+
# -*- SkipSchemaAnnotations
|
157
|
+
|
158
|
+
### Configuration in Rails
|
159
|
+
|
160
|
+
To generate a configuration file (in the form of a `.rake` file), to set
|
161
|
+
default options:
|
162
|
+
|
163
|
+
rails g annotate:install
|
164
|
+
|
165
|
+
Edit this file to control things like output format, where annotations are
|
166
|
+
added (top or bottom of file), and in which artifacts.
|
167
|
+
|
168
|
+
The generated rakefile `lib/tasks/auto_annotate_models.rake` also contains
|
169
|
+
`Annotate.load_tasks`. This adds a few rake tasks which duplicate command-line
|
170
|
+
functionality:
|
171
|
+
|
172
|
+
rake annotate_models # Add schema information (as comments) to model and fixture files
|
173
|
+
rake annotate_routes # Adds the route map to routes.rb
|
174
|
+
rake remove_annotation # Remove schema information from model and fixture files
|
175
|
+
|
176
|
+
By default, once you've generated a configuration file, annotate will be
|
177
|
+
executed whenever you run `rake db:migrate` (but only in development mode).
|
178
|
+
If you want to disable this behavior permanently,
|
179
|
+
edit the `.rake` file and change:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
'skip_on_db_migrate' => 'false',
|
183
|
+
```
|
184
|
+
|
185
|
+
To:
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
'skip_on_db_migrate' => 'true',
|
189
|
+
```
|
190
|
+
|
191
|
+
If you want to run `rake db:migrate` as a one-off without running annotate,
|
192
|
+
you can do so with a simple environment variable, instead of editing the
|
193
|
+
`.rake` file:
|
194
|
+
|
195
|
+
ANNOTATE_SKIP_ON_DB_MIGRATE=1 rake db:migrate
|
196
|
+
|
197
|
+
## Options
|
198
|
+
|
199
|
+
Usage: annotate [options] [model_file]*
|
200
|
+
--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
|
+
-d, --delete Remove annotations from all model files or the routes.rb file
|
202
|
+
-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)
|
203
|
+
--position
|
204
|
+
--pc, --position-in-class [before|top|after|bottom]
|
205
|
+
Place the annotations at the top (before) or the bottom (after) of the model file
|
206
|
+
--pf, --position-in-factory [before|top|after|bottom]
|
207
|
+
Place the annotations at the top (before) or the bottom (after) of any factory files
|
208
|
+
--px, --position-in-fixture [before|top|after|bottom]
|
209
|
+
Place the annotations at the top (before) or the bottom (after) of any fixture files
|
210
|
+
--pt, --position-in-test [before|top|after|bottom]
|
211
|
+
Place the annotations at the top (before) or the bottom (after) of any test files
|
212
|
+
--pr, --position-in-routes [before|top|after|bottom]
|
213
|
+
Place the annotations at the top (before) or the bottom (after) of the routes.rb file
|
214
|
+
--ps, --position-in-serializer [before|top|after|bottom]
|
215
|
+
Place the annotations at the top (before) or the bottom (after) of the serializer files
|
216
|
+
--w, --wrapper STR Wrap annotation with the text passed as parameter.
|
217
|
+
If --w option is used, the same text will be used as opening and closing
|
218
|
+
--wo, --wrapper-open STR Annotation wrapper opening.
|
219
|
+
--wc, --wrapper-close STR Annotation wrapper closing
|
220
|
+
-r, --routes Annotate routes.rb with the output of 'rake routes'
|
221
|
+
--models Annotate ActiveRecord models
|
222
|
+
-a, --active-admin Annotate active_admin models
|
223
|
+
-v, --version Show the current version of this gem
|
224
|
+
-m, --show-migration Include the migration version number in the annotation
|
225
|
+
-c, --show-check-constraints List the table's check constraints in the annotation
|
226
|
+
-k, --show-foreign-keys List the table's foreign key constraints in the annotation
|
227
|
+
--ck, --complete-foreign-keys
|
228
|
+
Complete foreign key names in the annotation
|
229
|
+
-i, --show-indexes List the table's database indexes in the annotation
|
230
|
+
-s, --simple-indexes Concat the column's related indexes in the annotation
|
231
|
+
--model-dir dir Annotate model files stored in dir rather than app/models, separate multiple dirs with commas
|
232
|
+
--root-dir dir Annotate files stored within root dir projects, separate multiple dirs with commas
|
233
|
+
--ignore-model-subdirects Ignore subdirectories of the models directory
|
234
|
+
--sort Sort columns alphabetically, rather than in creation order
|
235
|
+
--classified-sort Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns
|
236
|
+
-R, --require path Additional file to require before loading models, may be used multiple times
|
237
|
+
-e [tests,fixtures,factories,serializers],
|
238
|
+
--exclude Do not annotate fixtures, test files, factories, and/or serializers
|
239
|
+
-f [bare|rdoc|yard|markdown], Render Schema Infomation as plain/RDoc/YARD/Markdown
|
240
|
+
--format
|
241
|
+
--force Force new annotations even if there are no changes.
|
242
|
+
--frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files.
|
243
|
+
--timestamp Include timestamp in (routes) annotation
|
244
|
+
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
|
245
|
+
-I, --ignore-columns REGEX don't annotate columns that match a given REGEX (e.g. `annotate -I '^(id|updated_at|created_at)'`)
|
246
|
+
--ignore-routes REGEX don't annotate routes that match a given REGEX (e.g. `annotate -I '(mobile|resque|pghero)'`)_
|
247
|
+
--hide-limit-column-types VALUES
|
248
|
+
don't show limit for given column types, separated by commas (e.g. `integer,boolean,text`)
|
249
|
+
--hide-default-column-types VALUES
|
250
|
+
don't show default for given column types, separated by commas (e.g. `json,jsonb,hstore`)
|
251
|
+
--ignore-unknown-models don't display warnings for bad model files
|
252
|
+
--with-comment include database comments in model annotations
|
253
|
+
--with-comment-column include database comments in model annotations, as its own column, after all others
|
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
|
+
|
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`).
|
271
|
+
|
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
|
278
|
+
|
279
|
+
By default, columns will be sorted in database order (i.e. the order in which
|
280
|
+
migrations were run).
|
281
|
+
|
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`.
|
284
|
+
|
285
|
+
## Markdown
|
286
|
+
|
287
|
+
The format produced is actually MultiMarkdown, making use of the syntax
|
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:
|
292
|
+
|
293
|
+
--markup markdown
|
294
|
+
--markup-provider kramdown
|
295
|
+
|
296
|
+
Be sure to add this to your `Gemfile` as well:
|
297
|
+
|
298
|
+
gem 'kramdown', groups => [:development], require => false
|
299
|
+
|
300
|
+
## WARNING
|
301
|
+
|
302
|
+
**Don't add text after an automatically-created comment block.** This tool
|
303
|
+
will blow away the initial/final comment block in your models if it looks like
|
304
|
+
it was previously added by this gem.
|
305
|
+
|
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`:
|
308
|
+
|
309
|
+
$ git status
|
310
|
+
|
311
|
+
If you are not using a VCS (like Git, Subversion or similar), please tread
|
312
|
+
extra carefully, and consider using one.
|
313
|
+
|
314
|
+
## Links
|
315
|
+
|
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
|
323
|
+
|
324
|
+
|
325
|
+
## License
|
326
|
+
|
327
|
+
Released under the same license as Ruby. No Support. No Warranty.
|
328
|
+
|
329
|
+
## Authors
|
330
|
+
|
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/annot8.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'annotate/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'annot8'
|
9
|
+
s.version = Annotate.version
|
10
|
+
|
11
|
+
s.required_ruby_version = '>= 3.2.2'
|
12
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
13
|
+
s.authors = ['Alex Chaffee', 'Cuong Tran', 'Marcos Piccinini', 'Turadg Aleahmad', 'Jon Frisby', 'Benjamin Dunkley']
|
14
|
+
s.description = 'Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema. This fork of the "annotate" gemis built for Rails 8 and Ruby 3.2.2+'
|
15
|
+
s.email = ['ben@chemica.co.uk']
|
16
|
+
s.executables = ['annotate']
|
17
|
+
s.extra_rdoc_files = ['README.md', 'CHANGELOG.md']
|
18
|
+
s.files = `git ls-files -z LICENSE.txt *.md *.gemspec bin lib`.split("\x0")
|
19
|
+
s.homepage = 'https://github.com/chemica/annotate_models'
|
20
|
+
s.licenses = ['Ruby']
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
s.summary = 'Annotates Rails Models, routes, fixtures, and others based on the database schema.'
|
23
|
+
|
24
|
+
s.add_dependency('activerecord', ['>= 8.0.0', '< 9'])
|
25
|
+
s.add_dependency('rake', '>= 10.4', '< 14.0')
|
26
|
+
|
27
|
+
s.metadata = {
|
28
|
+
'bug_tracker_uri' => 'https://github.com/chemica/annotate_models/issues/',
|
29
|
+
'source_code_uri' => 'https://github.com/chemica/annotate_models.git',
|
30
|
+
'rubygems_mfa_required' => 'true'
|
31
|
+
}
|
32
|
+
end
|
data/bin/annotate
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
abort 'Please run annotate from the root of the project.' unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
begin
|
8
|
+
require 'bundler'
|
9
|
+
Bundler.setup
|
10
|
+
rescue StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
here = __dir__
|
14
|
+
$LOAD_PATH << "#{here}/../lib"
|
15
|
+
|
16
|
+
require 'annotate'
|
17
|
+
require 'annotate/parser'
|
18
|
+
|
19
|
+
Annotate.bootstrap_rake
|
20
|
+
|
21
|
+
options_result = Annotate::Parser.parse(ARGV)
|
22
|
+
|
23
|
+
exit if options_result[:exit]
|
24
|
+
|
25
|
+
options = Annotate.setup_options(
|
26
|
+
is_rake: ENV.fetch('is_rake', nil) && !ENV['is_rake'].empty?
|
27
|
+
)
|
28
|
+
Annotate.eager_load(options) if Annotate::Helpers.include_models?
|
29
|
+
|
30
|
+
AnnotateModels.send(options_result[:target_action], options) if Annotate::Helpers.include_models?
|
31
|
+
AnnotateRoutes.send(options_result[:target_action], options) if Annotate::Helpers.include_routes?
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AnnotateModels
|
4
|
+
# This module provides module method to get file paths.
|
5
|
+
module FilePatterns
|
6
|
+
# Controller files
|
7
|
+
CONTROLLER_DIR = File.join('app', 'controllers')
|
8
|
+
|
9
|
+
# Active admin registry files
|
10
|
+
ACTIVEADMIN_DIR = File.join('app', 'admin')
|
11
|
+
|
12
|
+
# Helper files
|
13
|
+
HELPER_DIR = File.join('app', 'helpers')
|
14
|
+
|
15
|
+
# File.join for windows reverse bar compat?
|
16
|
+
# I dont use windows, can`t test
|
17
|
+
UNIT_TEST_DIR = File.join('test', 'unit')
|
18
|
+
MODEL_TEST_DIR = File.join('test', 'models') # since rails 4.0
|
19
|
+
SPEC_MODEL_DIR = File.join('spec', 'models')
|
20
|
+
|
21
|
+
FIXTURE_TEST_DIR = File.join('test', 'fixtures')
|
22
|
+
FIXTURE_SPEC_DIR = File.join('spec', 'fixtures')
|
23
|
+
|
24
|
+
# Other test files
|
25
|
+
CONTROLLER_TEST_DIR = File.join('test', 'controllers')
|
26
|
+
CONTROLLER_SPEC_DIR = File.join('spec', 'controllers')
|
27
|
+
REQUEST_SPEC_DIR = File.join('spec', 'requests')
|
28
|
+
ROUTING_SPEC_DIR = File.join('spec', 'routing')
|
29
|
+
|
30
|
+
# Object Daddy http://github.com/flogic/object_daddy/tree/master
|
31
|
+
EXEMPLARS_TEST_DIR = File.join('test', 'exemplars')
|
32
|
+
EXEMPLARS_SPEC_DIR = File.join('spec', 'exemplars')
|
33
|
+
|
34
|
+
# Machinist http://github.com/notahat/machinist
|
35
|
+
BLUEPRINTS_TEST_DIR = File.join('test', 'blueprints')
|
36
|
+
BLUEPRINTS_SPEC_DIR = File.join('spec', 'blueprints')
|
37
|
+
|
38
|
+
# Factory Bot https://github.com/thoughtbot/factory_bot
|
39
|
+
FACTORY_BOT_TEST_DIR = File.join('test', 'factories')
|
40
|
+
FACTORY_BOT_SPEC_DIR = File.join('spec', 'factories')
|
41
|
+
|
42
|
+
# Fabrication https://github.com/paulelliott/fabrication.git
|
43
|
+
FABRICATORS_TEST_DIR = File.join('test', 'fabricators')
|
44
|
+
FABRICATORS_SPEC_DIR = File.join('spec', 'fabricators')
|
45
|
+
|
46
|
+
# Serializers https://github.com/rails-api/active_model_serializers
|
47
|
+
SERIALIZERS_DIR = File.join('app', 'serializers')
|
48
|
+
SERIALIZERS_TEST_DIR = File.join('test', 'serializers')
|
49
|
+
SERIALIZERS_SPEC_DIR = File.join('spec', 'serializers')
|
50
|
+
|
51
|
+
class << self
|
52
|
+
def generate(root_directory, pattern_type, options)
|
53
|
+
case pattern_type
|
54
|
+
when 'test' then test_files(root_directory)
|
55
|
+
when 'fixture' then fixture_files(root_directory)
|
56
|
+
when 'scaffold' then scaffold_files(root_directory)
|
57
|
+
when 'factory' then factory_files(root_directory)
|
58
|
+
when 'serializer' then serialize_files(root_directory)
|
59
|
+
when 'additional_file_patterns'
|
60
|
+
[options[:additional_file_patterns] || []].flatten
|
61
|
+
when 'controller'
|
62
|
+
[File.join(root_directory, CONTROLLER_DIR, '%PLURALIZED_MODEL_NAME%_controller.rb')]
|
63
|
+
when 'admin'
|
64
|
+
[
|
65
|
+
File.join(root_directory, ACTIVEADMIN_DIR, '%MODEL_NAME%.rb'),
|
66
|
+
File.join(root_directory, ACTIVEADMIN_DIR, '%PLURALIZED_MODEL_NAME%.rb')
|
67
|
+
]
|
68
|
+
when 'helper'
|
69
|
+
[File.join(root_directory, HELPER_DIR, '%PLURALIZED_MODEL_NAME%_helper.rb')]
|
70
|
+
else
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def test_files(root_directory)
|
78
|
+
[
|
79
|
+
File.join(root_directory, UNIT_TEST_DIR, '%MODEL_NAME%_test.rb'),
|
80
|
+
File.join(root_directory, MODEL_TEST_DIR, '%MODEL_NAME%_test.rb'),
|
81
|
+
File.join(root_directory, SPEC_MODEL_DIR, '%MODEL_NAME%_spec.rb')
|
82
|
+
]
|
83
|
+
end
|
84
|
+
|
85
|
+
def fixture_files(root_directory)
|
86
|
+
[
|
87
|
+
File.join(root_directory, FIXTURE_TEST_DIR, '%TABLE_NAME%.yml'),
|
88
|
+
File.join(root_directory, FIXTURE_SPEC_DIR, '%TABLE_NAME%.yml'),
|
89
|
+
File.join(root_directory, FIXTURE_TEST_DIR, '%PLURALIZED_MODEL_NAME%.yml'),
|
90
|
+
File.join(root_directory, FIXTURE_SPEC_DIR, '%PLURALIZED_MODEL_NAME%.yml')
|
91
|
+
]
|
92
|
+
end
|
93
|
+
|
94
|
+
def scaffold_files(root_directory)
|
95
|
+
[
|
96
|
+
File.join(root_directory, CONTROLLER_TEST_DIR, '%PLURALIZED_MODEL_NAME%_controller_test.rb'),
|
97
|
+
File.join(root_directory, CONTROLLER_SPEC_DIR, '%PLURALIZED_MODEL_NAME%_controller_spec.rb'),
|
98
|
+
File.join(root_directory, REQUEST_SPEC_DIR, '%PLURALIZED_MODEL_NAME%_spec.rb'),
|
99
|
+
File.join(root_directory, ROUTING_SPEC_DIR, '%PLURALIZED_MODEL_NAME%_routing_spec.rb')
|
100
|
+
]
|
101
|
+
end
|
102
|
+
|
103
|
+
def factory_files(root_directory)
|
104
|
+
[
|
105
|
+
File.join(root_directory, EXEMPLARS_TEST_DIR, '%MODEL_NAME%_exemplar.rb'),
|
106
|
+
File.join(root_directory, EXEMPLARS_SPEC_DIR, '%MODEL_NAME%_exemplar.rb'),
|
107
|
+
File.join(root_directory, BLUEPRINTS_TEST_DIR, '%MODEL_NAME%_blueprint.rb'),
|
108
|
+
File.join(root_directory, BLUEPRINTS_SPEC_DIR, '%MODEL_NAME%_blueprint.rb'),
|
109
|
+
File.join(root_directory, FACTORY_BOT_TEST_DIR, '%MODEL_NAME%_factory.rb'), # (old style)
|
110
|
+
File.join(root_directory, FACTORY_BOT_SPEC_DIR, '%MODEL_NAME%_factory.rb'), # (old style)
|
111
|
+
File.join(root_directory, FACTORY_BOT_TEST_DIR, '%TABLE_NAME%.rb'), # (new style)
|
112
|
+
File.join(root_directory, FACTORY_BOT_SPEC_DIR, '%TABLE_NAME%.rb'), # (new style)
|
113
|
+
File.join(root_directory, FACTORY_BOT_TEST_DIR, '%PLURALIZED_MODEL_NAME%.rb'), # (new style)
|
114
|
+
File.join(root_directory, FACTORY_BOT_SPEC_DIR, '%PLURALIZED_MODEL_NAME%.rb'), # (new style)
|
115
|
+
File.join(root_directory, FABRICATORS_TEST_DIR, '%MODEL_NAME%_fabricator.rb'),
|
116
|
+
File.join(root_directory, FABRICATORS_SPEC_DIR, '%MODEL_NAME%_fabricator.rb')
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
120
|
+
def serialize_files(root_directory)
|
121
|
+
[
|
122
|
+
File.join(root_directory, SERIALIZERS_DIR, '%MODEL_NAME%_serializer.rb'),
|
123
|
+
File.join(root_directory, SERIALIZERS_TEST_DIR, '%MODEL_NAME%_serializer_test.rb'),
|
124
|
+
File.join(root_directory, SERIALIZERS_SPEC_DIR, '%MODEL_NAME%_serializer_spec.rb')
|
125
|
+
]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|