annotated 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/AUTHORS.md +34 -0
- data/CHANGELOG.md +328 -0
- data/LICENSE.txt +55 -0
- data/README.md +331 -0
- data/RELEASE.md +19 -0
- data/annotated.gemspec +45 -0
- data/bin/annotated +32 -0
- data/lib/annotated/active_record_patch.rb +9 -0
- data/lib/annotated/annotate_models/file_patterns.rb +127 -0
- data/lib/annotated/annotate_models.rb +990 -0
- data/lib/annotated/annotate_routes/header_generator.rb +113 -0
- data/lib/annotated/annotate_routes/helpers.rb +69 -0
- data/lib/annotated/annotate_routes.rb +119 -0
- data/lib/annotated/constants.rb +39 -0
- data/lib/annotated/helpers.rb +30 -0
- data/lib/annotated/parser.rb +314 -0
- data/lib/annotated/tasks.rb +6 -0
- data/lib/annotated/version.rb +5 -0
- data/lib/annotated.rb +147 -0
- data/lib/generators/annotate/USAGE +4 -0
- data/lib/generators/annotate/install_generator.rb +15 -0
- data/lib/generators/annotate/templates/auto_annotate_models.rake +61 -0
- data/lib/tasks/annotate_models.rake +72 -0
- data/lib/tasks/annotate_models_migrate.rake +63 -0
- data/lib/tasks/annotate_routes.rake +31 -0
- data/potato.md +41 -0
- metadata +101 -0
data/README.md
ADDED
@@ -0,0 +1,331 @@
|
|
1
|
+
## Annotated (fork of Annotate aka AnnotateModels)
|
2
|
+
|
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
|
+
[![CI Status](https://github.com/ctran/annotate_models/workflows/CI/badge.svg)](https://github.com/ctran/annotate_models/actions?workflow=CI)
|
6
|
+
[![Coveralls](https://coveralls.io/repos/ctran/annotate_models/badge.svg?branch=develop)](https://coveralls.io/r/ctran/annotate_models?branch=develop)
|
7
|
+
[![Maintenability](https://codeclimate.com/github/ctran/annotate_models/badges/gpa.svg)](https://codeclimate.com/github/ctran/annotate_models)
|
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 the annotate gem 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
|
+
Annotated.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 'annotate'
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
Into Gemfile from Github:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
group :development do
|
93
|
+
gem 'annotate', git: 'https://github.com/ctran/annotate_models.git'
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
Into environment gems from rubygems.org:
|
98
|
+
|
99
|
+
gem install annotate
|
100
|
+
|
101
|
+
Into environment gems from Github checkout:
|
102
|
+
|
103
|
+
git clone https://github.com/ctran/annotate_models.git annotate_models
|
104
|
+
cd annotate_models
|
105
|
+
rake gem
|
106
|
+
gem install dist/annotate-*.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 `Annotated.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
|
+
`Annotated.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/annotated.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/annotated/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "annotated"
|
7
|
+
spec.version = Annotated.version
|
8
|
+
spec.authors = [
|
9
|
+
"Stefan Froelich",
|
10
|
+
"Alex Chaffee",
|
11
|
+
"Cuong Tran",
|
12
|
+
"Marcos Piccinini",
|
13
|
+
"Turadg Aleahmad",
|
14
|
+
"Jon Frisby"
|
15
|
+
]
|
16
|
+
spec.email = [
|
17
|
+
"sfroelich01@gmail.com",
|
18
|
+
"alex@stinky.com",
|
19
|
+
"cuong.tran@gmail.com",
|
20
|
+
"x@nofxx.com",
|
21
|
+
"turadg@aleahmad.net",
|
22
|
+
"jon@cloudability.com"
|
23
|
+
]
|
24
|
+
|
25
|
+
spec.summary = "Annotates Rails Models, routes, fixtures, and others based on the database schema."
|
26
|
+
spec.description = "Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema."
|
27
|
+
spec.homepage = "https://github.com/thedumbtechguy/annotated"
|
28
|
+
spec.license = "Ruby"
|
29
|
+
spec.required_ruby_version = ">= 3.2"
|
30
|
+
|
31
|
+
spec.metadata = {
|
32
|
+
"homepage_uri" => spec.homepage,
|
33
|
+
"bug_tracker_uri" => "https://github.com/thedumbtechguy/annotated/issues",
|
34
|
+
"documentation_uri" => "https://github.com/thedumbtechguy/annotated",
|
35
|
+
"source_code_uri" => "https://github.com/thedumbtechguy/annotated",
|
36
|
+
"changelog_uri" => "https://github.com/thedumbtechguy/annotated/blob/master/CHANGELOG.md"
|
37
|
+
}
|
38
|
+
|
39
|
+
spec.files = Dir.glob(%w[LICENSE.txt *.md *.gemspec bin/* lib/**/*])
|
40
|
+
spec.bindir = "bin"
|
41
|
+
spec.executables = ["annotated"]
|
42
|
+
spec.require_paths = ["lib"]
|
43
|
+
|
44
|
+
spec.add_dependency "activerecord", ">= 3.2"
|
45
|
+
end
|
data/bin/annotated
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
unless File.exist?('./Rakefile') || File.exist?('./Gemfile')
|
4
|
+
abort 'Please run annotate from the root of the project.'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
begin
|
9
|
+
require 'bundler'
|
10
|
+
Bundler.setup
|
11
|
+
rescue StandardError
|
12
|
+
end
|
13
|
+
|
14
|
+
here = File.expand_path(File.dirname __FILE__)
|
15
|
+
$LOAD_PATH << "#{here}/../lib"
|
16
|
+
|
17
|
+
require 'annotated'
|
18
|
+
require 'annotated/parser'
|
19
|
+
|
20
|
+
Annotated.bootstrap_rake
|
21
|
+
|
22
|
+
options_result = Annotated::Parser.parse(ARGV)
|
23
|
+
|
24
|
+
exit if options_result[:exit]
|
25
|
+
|
26
|
+
options = Annotated.setup_options(
|
27
|
+
is_rake: ENV['is_rake'] && !ENV['is_rake'].empty?
|
28
|
+
)
|
29
|
+
Annotated.eager_load(options) if Annotated::Helpers.include_models?
|
30
|
+
|
31
|
+
AnnotatedModels.send(options_result[:target_action], options) if Annotated::Helpers.include_models?
|
32
|
+
AnnotatedRoutes.send(options_result[:target_action], options) if Annotated::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
|