Commit 504c2674 by Daniel Evans

Annotate conventionally named serializers

parent a2688605
...@@ -36,7 +36,7 @@ OptionParser.new do |opts| ...@@ -36,7 +36,7 @@ OptionParser.new do |opts|
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/routes file(s)") do |p| "Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/routes file(s)") do |p|
ENV['position'] = p ENV['position'] = p
[ [
'position_in_class','position_in_factory','position_in_fixture','position_in_test', 'position_in_routes' 'position_in_class','position_in_factory','position_in_fixture','position_in_test', 'position_in_routes', 'position_in_serializer'
].each do |key| ].each do |key|
ENV[key] = p unless(has_set_position[key]) ENV[key] = p unless(has_set_position[key])
end end
...@@ -72,6 +72,12 @@ OptionParser.new do |opts| ...@@ -72,6 +72,12 @@ OptionParser.new do |opts|
has_set_position['position_in_routes'] = true has_set_position['position_in_routes'] = true
end end
opts.on('--ps', '--position-in-serializer [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of the serializer files") do |p|
ENV['position_in_serializer'] = p
has_set_position['position_in_serializer'] = true
end
opts.on('-r', '--routes', opts.on('-r', '--routes',
"Annotate routes.rb with the output of 'rake routes'") do "Annotate routes.rb with the output of 'rake routes'") do
target = { target = {
...@@ -124,7 +130,7 @@ OptionParser.new do |opts| ...@@ -124,7 +130,7 @@ OptionParser.new do |opts|
end end
end end
opts.on('-e', '--exclude [tests,fixtures,factories]', Array, "Do not annotate fixtures, test files, and/or factories") do |exclusions| opts.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
exclusions ||= %w(tests fixtures factories) exclusions ||= %w(tests fixtures factories)
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" } exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
end end
......
...@@ -18,11 +18,13 @@ module Annotate ...@@ -18,11 +18,13 @@ module Annotate
POSITION_OPTIONS=[ POSITION_OPTIONS=[
:position_in_routes, :position_in_class, :position_in_test, :position_in_routes, :position_in_class, :position_in_test,
:position_in_fixture, :position_in_factory, :position, :position_in_fixture, :position_in_factory, :position,
:position_in_serializer,
] ]
FLAG_OPTIONS=[ FLAG_OPTIONS=[
:show_indexes, :simple_indexes, :include_version, :exclude_tests, :show_indexes, :simple_indexes, :include_version, :exclude_tests,
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir, :exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace, :timestamp :format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
:timestamp, :exclude_serializers
] ]
OTHER_OPTIONS=[ OTHER_OPTIONS=[
:model_dir, :ignore_columns :model_dir, :ignore_columns
......
...@@ -31,6 +31,12 @@ module AnnotateModels ...@@ -31,6 +31,12 @@ module AnnotateModels
FABRICATORS_TEST_DIR = File.join("test", "fabricators") FABRICATORS_TEST_DIR = File.join("test", "fabricators")
FABRICATORS_SPEC_DIR = File.join("spec", "fabricators") FABRICATORS_SPEC_DIR = File.join("spec", "fabricators")
# Serializers https://github.com/rails-api/active_model_serializers
SERIALIZERS_DIR = File.join("app", "serializers")
SERIALIZERS_TEST_DIR = File.join("test", "serializers")
SERIALIZERS_SPEC_DIR = File.join("spec", "serializers")
TEST_PATTERNS = [ TEST_PATTERNS = [
File.join(UNIT_TEST_DIR, "%MODEL_NAME%_test.rb"), File.join(UNIT_TEST_DIR, "%MODEL_NAME%_test.rb"),
File.join(MODEL_TEST_DIR, "%MODEL_NAME%_test.rb"), File.join(MODEL_TEST_DIR, "%MODEL_NAME%_test.rb"),
...@@ -55,6 +61,12 @@ module AnnotateModels ...@@ -55,6 +61,12 @@ module AnnotateModels
File.join(FABRICATORS_SPEC_DIR, "%MODEL_NAME%_fabricator.rb"), File.join(FABRICATORS_SPEC_DIR, "%MODEL_NAME%_fabricator.rb"),
] ]
SERIALIZER_PATTERNS = [
File.join(SERIALIZERS_DIR, "%MODEL_NAME%_serializer.rb"),
File.join(SERIALIZERS_TEST_DIR, "%MODEL_NAME%_serializer_spec.rb"),
File.join(SERIALIZERS_SPEC_DIR, "%MODEL_NAME%_serializer_spec.rb")
]
# Don't show limit (#) on these column types # Don't show limit (#) on these column types
# Example: show "integer" instead of "integer(4)" # Example: show "integer" instead of "integer(4)"
NO_LIMIT_COL_TYPES = ["integer", "boolean"] NO_LIMIT_COL_TYPES = ["integer", "boolean"]
...@@ -302,25 +314,17 @@ module AnnotateModels ...@@ -302,25 +314,17 @@ module AnnotateModels
did_annotate = true did_annotate = true
end end
unless options[:exclude_tests] %w(test fixture factory serializer).each do |key|
did_annotate = TEST_PATTERNS. exclusion_key = "exclude_#{key.pluralize}".to_sym
map { |file| resolve_filename(file, model_name, table_name) }. patterns_constant = "#{key.upcase}_PATTERNS".to_sym
map { |file| annotate_one_file(file, info, :position_in_test, options_with_position(options, :position_in_test)) }. position_key = "position_in_#{key}".to_sym
detect { |result| result } || did_annotate
end
unless options[:exclude_fixtures] unless options[exclusion_key]
did_annotate = FIXTURE_PATTERNS. did_annotate = self.const_get(patterns_constant).
map { |file| resolve_filename(file, model_name, table_name) }. map { |file| resolve_filename(file, model_name, table_name) }.
map { |file| annotate_one_file(file, info, :position_in_fixture, options_with_position(options, :position_in_fixture)) }. map { |file| annotate_one_file(file, info, position_key, options_with_position(options, position_key)) }.
detect { |result| result } || did_annotate detect { |result| result } || did_annotate
end end
unless options[:exclude_factories]
did_annotate = FACTORY_PATTERNS.
map { |file| resolve_filename(file, model_name, table_name) }.
map { |file| annotate_one_file(file, info, :position_in_factory, options_with_position(options, :position_in_factory)) }.
detect { |result| result } || did_annotate
end end
return did_annotate return did_annotate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment