@@ -31,6 +31,12 @@ module AnnotateModels
31
31
FABRICATORS_TEST_DIR = File . join ( "test" , "fabricators" )
32
32
FABRICATORS_SPEC_DIR = File . join ( "spec" , "fabricators" )
33
33
34
+ # Serializers https://github.com/rails-api/active_model_serializers
35
+ SERIALIZERS_DIR = File . join ( "app" , "serializers" )
36
+ SERIALIZERS_TEST_DIR = File . join ( "test" , "serializers" )
37
+ SERIALIZERS_SPEC_DIR = File . join ( "spec" , "serializers" )
38
+
39
+
34
40
TEST_PATTERNS = [
35
41
File . join ( UNIT_TEST_DIR , "%MODEL_NAME%_test.rb" ) ,
36
42
File . join ( MODEL_TEST_DIR , "%MODEL_NAME%_test.rb" ) ,
@@ -55,6 +61,12 @@ module AnnotateModels
55
61
File . join ( FABRICATORS_SPEC_DIR , "%MODEL_NAME%_fabricator.rb" ) ,
56
62
]
57
63
64
+ SERIALIZER_PATTERNS = [
65
+ File . join ( SERIALIZERS_DIR , "%MODEL_NAME%_serializer.rb" ) ,
66
+ File . join ( SERIALIZERS_TEST_DIR , "%MODEL_NAME%_serializer_spec.rb" ) ,
67
+ File . join ( SERIALIZERS_SPEC_DIR , "%MODEL_NAME%_serializer_spec.rb" )
68
+ ]
69
+
58
70
# Don't show limit (#) on these column types
59
71
# Example: show "integer" instead of "integer(4)"
60
72
NO_LIMIT_COL_TYPES = [ "integer" , "boolean" ]
@@ -302,25 +314,17 @@ def annotate(klass, file, header, options={})
302
314
did_annotate = true
303
315
end
304
316
305
- unless options [ :exclude_tests ]
306
- did_annotate = TEST_PATTERNS .
307
- map { |file | resolve_filename ( file , model_name , table_name ) } .
308
- map { |file | annotate_one_file ( file , info , :position_in_test , options_with_position ( options , :position_in_test ) ) } .
309
- detect { |result | result } || did_annotate
310
- end
317
+ %w( test fixture factory serializer ) . each do |key |
318
+ exclusion_key = "exclude_#{ key . pluralize } " . to_sym
319
+ patterns_constant = "#{ key . upcase } _PATTERNS" . to_sym
320
+ position_key = "position_in_#{ key } " . to_sym
311
321
312
- unless options [ :exclude_fixtures ]
313
- did_annotate = FIXTURE_PATTERNS .
314
- map { |file | resolve_filename ( file , model_name , table_name ) } .
315
- map { |file | annotate_one_file ( file , info , :position_in_fixture , options_with_position ( options , :position_in_fixture ) ) } .
316
- detect { |result | result } || did_annotate
317
- end
318
-
319
- unless options [ :exclude_factories ]
320
- did_annotate = FACTORY_PATTERNS .
321
- map { |file | resolve_filename ( file , model_name , table_name ) } .
322
- map { |file | annotate_one_file ( file , info , :position_in_factory , options_with_position ( options , :position_in_factory ) ) } .
323
- detect { |result | result } || did_annotate
322
+ unless options [ exclusion_key ]
323
+ did_annotate = self . const_get ( patterns_constant ) .
324
+ map { |file | resolve_filename ( file , model_name , table_name ) } .
325
+ map { |file | annotate_one_file ( file , info , position_key , options_with_position ( options , position_key ) ) } .
326
+ detect { |result | result } || did_annotate
327
+ end
324
328
end
325
329
326
330
return did_annotate
0 commit comments