3
3
require 'bigdecimal'
4
4
5
5
require 'annotate/constants'
6
+ require_relative 'annotate_models/file_patterns'
6
7
7
8
module AnnotateModels
8
9
# Annotate Models plugin use this header
@@ -16,50 +17,6 @@ module AnnotateModels
16
17
17
18
MATCHED_TYPES = %w( test fixture factory serializer scaffold controller helper ) . freeze
18
19
19
- # File.join for windows reverse bar compat?
20
- # I dont use windows, can`t test
21
- UNIT_TEST_DIR = File . join ( 'test' , "unit" )
22
- MODEL_TEST_DIR = File . join ( 'test' , "models" ) # since rails 4.0
23
- SPEC_MODEL_DIR = File . join ( 'spec' , "models" )
24
- FIXTURE_TEST_DIR = File . join ( 'test' , "fixtures" )
25
- FIXTURE_SPEC_DIR = File . join ( 'spec' , "fixtures" )
26
-
27
- # Other test files
28
- CONTROLLER_TEST_DIR = File . join ( 'test' , "controllers" )
29
- CONTROLLER_SPEC_DIR = File . join ( 'spec' , "controllers" )
30
- REQUEST_SPEC_DIR = File . join ( 'spec' , "requests" )
31
- ROUTING_SPEC_DIR = File . join ( 'spec' , "routing" )
32
-
33
- # Object Daddy http://github.com/flogic/object_daddy/tree/master
34
- EXEMPLARS_TEST_DIR = File . join ( 'test' , "exemplars" )
35
- EXEMPLARS_SPEC_DIR = File . join ( 'spec' , "exemplars" )
36
-
37
- # Machinist http://github.com/notahat/machinist
38
- BLUEPRINTS_TEST_DIR = File . join ( 'test' , "blueprints" )
39
- BLUEPRINTS_SPEC_DIR = File . join ( 'spec' , "blueprints" )
40
-
41
- # Factory Bot https://github.com/thoughtbot/factory_bot
42
- FACTORY_BOT_TEST_DIR = File . join ( 'test' , "factories" )
43
- FACTORY_BOT_SPEC_DIR = File . join ( 'spec' , "factories" )
44
-
45
- # Fabrication https://github.com/paulelliott/fabrication.git
46
- FABRICATORS_TEST_DIR = File . join ( 'test' , "fabricators" )
47
- FABRICATORS_SPEC_DIR = File . join ( 'spec' , "fabricators" )
48
-
49
- # Serializers https://github.com/rails-api/active_model_serializers
50
- SERIALIZERS_DIR = File . join ( 'app' , "serializers" )
51
- SERIALIZERS_TEST_DIR = File . join ( 'test' , "serializers" )
52
- SERIALIZERS_SPEC_DIR = File . join ( 'spec' , "serializers" )
53
-
54
- # Controller files
55
- CONTROLLER_DIR = File . join ( 'app' , "controllers" )
56
-
57
- # Active admin registry files
58
- ACTIVEADMIN_DIR = File . join ( 'app' , "admin" )
59
-
60
- # Helper files
61
- HELPER_DIR = File . join ( 'app' , "helpers" )
62
-
63
20
# Don't show limit (#) on these column types
64
21
# Example: show "integer" instead of "integer(4)"
65
22
NO_LIMIT_COL_TYPES = %w( integer bigint boolean ) . freeze
@@ -110,82 +67,11 @@ def root_dir
110
67
111
68
attr_writer :root_dir
112
69
113
- def test_files ( root_directory )
114
- [
115
- File . join ( root_directory , UNIT_TEST_DIR , "%MODEL_NAME%_test.rb" ) ,
116
- File . join ( root_directory , MODEL_TEST_DIR , "%MODEL_NAME%_test.rb" ) ,
117
- File . join ( root_directory , SPEC_MODEL_DIR , "%MODEL_NAME%_spec.rb" )
118
- ]
119
- end
120
-
121
- def fixture_files ( root_directory )
122
- [
123
- File . join ( root_directory , FIXTURE_TEST_DIR , "%TABLE_NAME%.yml" ) ,
124
- File . join ( root_directory , FIXTURE_SPEC_DIR , "%TABLE_NAME%.yml" ) ,
125
- File . join ( root_directory , FIXTURE_TEST_DIR , "%PLURALIZED_MODEL_NAME%.yml" ) ,
126
- File . join ( root_directory , FIXTURE_SPEC_DIR , "%PLURALIZED_MODEL_NAME%.yml" )
127
- ]
128
- end
129
-
130
- def scaffold_files ( root_directory )
131
- [
132
- File . join ( root_directory , CONTROLLER_TEST_DIR , "%PLURALIZED_MODEL_NAME%_controller_test.rb" ) ,
133
- File . join ( root_directory , CONTROLLER_SPEC_DIR , "%PLURALIZED_MODEL_NAME%_controller_spec.rb" ) ,
134
- File . join ( root_directory , REQUEST_SPEC_DIR , "%PLURALIZED_MODEL_NAME%_spec.rb" ) ,
135
- File . join ( root_directory , ROUTING_SPEC_DIR , "%PLURALIZED_MODEL_NAME%_routing_spec.rb" )
136
- ]
137
- end
138
-
139
- def factory_files ( root_directory )
140
- [
141
- File . join ( root_directory , EXEMPLARS_TEST_DIR , "%MODEL_NAME%_exemplar.rb" ) ,
142
- File . join ( root_directory , EXEMPLARS_SPEC_DIR , "%MODEL_NAME%_exemplar.rb" ) ,
143
- File . join ( root_directory , BLUEPRINTS_TEST_DIR , "%MODEL_NAME%_blueprint.rb" ) ,
144
- File . join ( root_directory , BLUEPRINTS_SPEC_DIR , "%MODEL_NAME%_blueprint.rb" ) ,
145
- File . join ( root_directory , FACTORY_BOT_TEST_DIR , "%MODEL_NAME%_factory.rb" ) , # (old style)
146
- File . join ( root_directory , FACTORY_BOT_SPEC_DIR , "%MODEL_NAME%_factory.rb" ) , # (old style)
147
- File . join ( root_directory , FACTORY_BOT_TEST_DIR , "%TABLE_NAME%.rb" ) , # (new style)
148
- File . join ( root_directory , FACTORY_BOT_SPEC_DIR , "%TABLE_NAME%.rb" ) , # (new style)
149
- File . join ( root_directory , FACTORY_BOT_TEST_DIR , "%PLURALIZED_MODEL_NAME%.rb" ) , # (new style)
150
- File . join ( root_directory , FACTORY_BOT_SPEC_DIR , "%PLURALIZED_MODEL_NAME%.rb" ) , # (new style)
151
- File . join ( root_directory , FABRICATORS_TEST_DIR , "%MODEL_NAME%_fabricator.rb" ) ,
152
- File . join ( root_directory , FABRICATORS_SPEC_DIR , "%MODEL_NAME%_fabricator.rb" )
153
- ]
154
- end
155
-
156
- def serialize_files ( root_directory )
157
- [
158
- File . join ( root_directory , SERIALIZERS_DIR , "%MODEL_NAME%_serializer.rb" ) ,
159
- File . join ( root_directory , SERIALIZERS_TEST_DIR , "%MODEL_NAME%_serializer_test.rb" ) ,
160
- File . join ( root_directory , SERIALIZERS_SPEC_DIR , "%MODEL_NAME%_serializer_spec.rb" )
161
- ]
162
- end
163
-
164
- def files_by_pattern ( root_directory , pattern_type , options )
165
- case pattern_type
166
- when 'test' then test_files ( root_directory )
167
- when 'fixture' then fixture_files ( root_directory )
168
- when 'scaffold' then scaffold_files ( root_directory )
169
- when 'factory' then factory_files ( root_directory )
170
- when 'serializer' then serialize_files ( root_directory )
171
- when 'additional_file_patterns'
172
- [ options [ :additional_file_patterns ] || [ ] ] . flatten
173
- when 'controller'
174
- [ File . join ( root_directory , CONTROLLER_DIR , "%PLURALIZED_MODEL_NAME%_controller.rb" ) ]
175
- when 'admin'
176
- [ File . join ( root_directory , ACTIVEADMIN_DIR , "%MODEL_NAME%.rb" ) ]
177
- when 'helper'
178
- [ File . join ( root_directory , HELPER_DIR , "%PLURALIZED_MODEL_NAME%_helper.rb" ) ]
179
- else
180
- [ ]
181
- end
182
- end
183
-
184
70
def get_patterns ( options , pattern_types = [ ] )
185
71
current_patterns = [ ]
186
72
root_dir . each do |root_directory |
187
73
Array ( pattern_types ) . each do |pattern_type |
188
- patterns = files_by_pattern ( root_directory , pattern_type , options )
74
+ patterns = FilePatterns . generate ( root_directory , pattern_type , options )
189
75
190
76
current_patterns += if pattern_type . to_sym == :additional_file_patterns
191
77
patterns
0 commit comments