Skip to content

Commit 2ea4402

Browse files
committed
Merge remote-tracking branch 'upstream/pr/977' into community-maintained
2 parents f67d716 + e7875ac commit 2ea4402

File tree

6 files changed

+74
-50
lines changed

6 files changed

+74
-50
lines changed

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ def matched_types(options)
521521
# :position_in_fixture<Symbol>:: where to place the annotated section in fixture file
522522
# :position_in_factory<Symbol>:: where to place the annotated section in factory file
523523
# :position_in_serializer<Symbol>:: where to place the annotated section in serializer file
524+
# :position_in_additional_file_patterns<Symbol>:: where to place the annotated section in files that match additional patterns
524525
# :exclude_tests<Symbol>:: whether to skip modification of test/spec files
525526
# :exclude_fixtures<Symbol>:: whether to skip modification of fixture files
526527
# :exclude_factories<Symbol>:: whether to skip modification of factory files

lib/annotate/constants.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Constants
88
POSITION_OPTIONS = [
99
:position_in_routes, :position_in_class, :position_in_test,
1010
:position_in_fixture, :position_in_factory, :position,
11-
:position_in_serializer
11+
:position_in_serializer, :position_in_additional_file_patterns
1212
].freeze
1313

1414
FLAG_OPTIONS = [

lib/annotate/parser.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def self.parse(args, env = {})
1515
}.freeze
1616

1717
ANNOTATION_POSITIONS = %w[before top after bottom].freeze
18-
FILE_TYPE_POSITIONS = %w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer].freeze
18+
FILE_TYPE_POSITIONS = %w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer position_in_additional_file_patterns].freeze
1919
EXCLUSION_LIST = %w[tests fixtures factories serializers].freeze
2020
FORMAT_TYPES = %w[bare rdoc yard markdown].freeze
2121

@@ -124,6 +124,14 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength,
124124
has_set_position['position_in_serializer'] = true
125125
end
126126

127+
option_parser.on('--pa',
128+
'--position-in-additional-file-patterns [before|top|after|bottom]',
129+
ANNOTATION_POSITIONS,
130+
'Place the annotations at the top (before) or the bottom (after) of files that match additional patterns') do |position_in_additional_file_patterns|
131+
env['position_in_additional_file_patterns'] = position_in_additional_file_patterns
132+
has_set_position['position_in_additional_file_patterns'] = true
133+
end
134+
127135
option_parser.on('--w',
128136
'--wrapper STR',
129137
'Wrap annotation with the text passed as parameter.',

lib/generators/annotate/templates/auto_annotate_models.rake

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,52 @@ if Rails.env.development?
77
# You can override any of these by setting an environment variable of the
88
# same name.
99
Annotate.set_defaults(
10-
'active_admin' => 'false',
11-
'additional_file_patterns' => [],
12-
'routes' => 'false',
13-
'models' => 'true',
14-
'position_in_routes' => 'before',
15-
'position_in_class' => 'before',
16-
'position_in_test' => 'before',
17-
'position_in_fixture' => 'before',
18-
'position_in_factory' => 'before',
19-
'position_in_serializer' => 'before',
20-
'show_check_constraints' => 'false',
21-
'show_foreign_keys' => 'true',
22-
'show_complete_foreign_keys' => 'false',
23-
'show_indexes' => 'true',
24-
'simple_indexes' => 'false',
25-
'model_dir' => 'app/models',
26-
'root_dir' => '',
27-
'include_version' => 'false',
28-
'require' => '',
29-
'exclude_tests' => 'false',
30-
'exclude_fixtures' => 'false',
31-
'exclude_factories' => 'false',
32-
'exclude_serializers' => 'false',
33-
'exclude_scaffolds' => 'true',
34-
'exclude_controllers' => 'true',
35-
'exclude_helpers' => 'true',
36-
'exclude_sti_subclasses' => 'false',
37-
'ignore_model_sub_dir' => 'false',
38-
'ignore_columns' => nil,
39-
'ignore_routes' => nil,
40-
'ignore_unknown_models' => 'false',
41-
'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(",") %>',
42-
'hide_default_column_types' => '<%= AnnotateModels::NO_DEFAULT_COL_TYPES.join(",") %>',
43-
'skip_on_db_migrate' => 'false',
44-
'format_bare' => 'true',
45-
'format_rdoc' => 'false',
46-
'format_yard' => 'false',
47-
'format_markdown' => 'false',
48-
'sort' => 'false',
49-
'force' => 'false',
50-
'frozen' => 'false',
51-
'classified_sort' => 'true',
52-
'trace' => 'false',
53-
'wrapper_open' => nil,
54-
'wrapper_close' => nil,
55-
'with_comment' => 'true',
56-
'with_comment_column' => 'false'
10+
'active_admin' => 'false',
11+
'additional_file_patterns' => [],
12+
'routes' => 'false',
13+
'models' => 'true',
14+
'position_in_routes' => 'before',
15+
'position_in_class' => 'before',
16+
'position_in_test' => 'before',
17+
'position_in_fixture' => 'before',
18+
'position_in_factory' => 'before',
19+
'position_in_serializer' => 'before',
20+
'position_in_additional_file_patterns' => 'before',
21+
'show_foreign_keys' => 'true',
22+
'show_complete_foreign_keys' => 'false',
23+
'show_indexes' => 'true',
24+
'simple_indexes' => 'false',
25+
'model_dir' => 'app/models',
26+
'root_dir' => '',
27+
'include_version' => 'false',
28+
'require' => '',
29+
'exclude_tests' => 'false',
30+
'exclude_fixtures' => 'false',
31+
'exclude_factories' => 'false',
32+
'exclude_serializers' => 'false',
33+
'exclude_scaffolds' => 'true',
34+
'exclude_controllers' => 'true',
35+
'exclude_helpers' => 'true',
36+
'exclude_sti_subclasses' => 'false',
37+
'ignore_model_sub_dir' => 'false',
38+
'ignore_columns' => nil,
39+
'ignore_routes' => nil,
40+
'ignore_unknown_models' => 'false',
41+
'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(",") %>',
42+
'hide_default_column_types' => '<%= AnnotateModels::NO_DEFAULT_COL_TYPES.join(",") %>',
43+
'skip_on_db_migrate' => 'false',
44+
'format_bare' => 'true',
45+
'format_rdoc' => 'false',
46+
'format_yard' => 'false',
47+
'format_markdown' => 'false',
48+
'sort' => 'false',
49+
'force' => 'false',
50+
'frozen' => 'false',
51+
'classified_sort' => 'true',
52+
'trace' => 'false',
53+
'wrapper_open' => nil,
54+
'wrapper_close' => nil,
55+
'with_comment' => 'true'
5756
)
5857
end
5958

lib/tasks/annotate_models.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ task annotate_models: :environment do
1818
options[:position_in_factory] = Annotate::Helpers.fallback(ENV['position_in_factory'], ENV['position'])
1919
options[:position_in_test] = Annotate::Helpers.fallback(ENV['position_in_test'], ENV['position'])
2020
options[:position_in_serializer] = Annotate::Helpers.fallback(ENV['position_in_serializer'], ENV['position'])
21-
options[:show_check_constraints] = Annotate::Helpers.true?(ENV['show_check_constraints'])
21+
options[:position_in_additional_file_patterns] = Annotate::Helpers.fallback(ENV['position_in_additional_file_patterns'], ENV['position'])
2222
options[:show_foreign_keys] = Annotate::Helpers.true?(ENV['show_foreign_keys'])
2323
options[:show_complete_foreign_keys] = Annotate::Helpers.true?(ENV['show_complete_foreign_keys'])
2424
options[:show_indexes] = Annotate::Helpers.true?(ENV['show_indexes'])

spec/lib/annotate/parser_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ module Annotate # rubocop:disable Metrics/ModuleLength
174174
end
175175
end
176176

177+
%w[--pa --position-in-additional-file-patterns].each do |option|
178+
describe option do
179+
let(:env_key) { 'position_in_additional_file_patterns' }
180+
181+
Parser::ANNOTATION_POSITIONS.each do |position|
182+
context "when specifying #{position}" do
183+
it "sets the ENV variable to #{position}" do
184+
allow(ENV).to receive(:[]=)
185+
Parser.parse([option, position])
186+
expect(ENV).to have_received(:[]=).with(env_key, position)
187+
end
188+
end
189+
end
190+
end
191+
end
192+
177193
%w[--w --wrapper].each do |option|
178194
describe option do
179195
let(:env_key) { 'wrapper' }

0 commit comments

Comments
 (0)