Skip to content

Commit 175c2a0

Browse files
committed
Annotate controllers for models: ctran#293
1 parent 7c2d14b commit 175c2a0

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

lib/annotate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Annotate
2727
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
2828
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
2929
:timestamp, :exclude_serializers, :classified_sort, :show_foreign_keys,
30-
:exclude_scaffolds
30+
:exclude_scaffolds, :exclude_controllers
3131
]
3232
OTHER_OPTIONS=[
3333
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :wrapper

lib/annotate/annotate_models.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ module AnnotateModels
4444
SERIALIZERS_TEST_DIR = File.join("test", "serializers")
4545
SERIALIZERS_SPEC_DIR = File.join("spec", "serializers")
4646

47+
# Controller files
48+
CONTROLLER_DIR = File.join("app", "controllers")
49+
4750
# Don't show limit (#) on these column types
4851
# Example: show "integer" instead of "integer(4)"
4952
NO_LIMIT_COL_TYPES = ["integer", "boolean"]
@@ -109,6 +112,10 @@ def get_patterns(pattern_types)
109112
File.join(root_directory, SERIALIZERS_TEST_DIR, "%MODEL_NAME%_serializer_spec.rb"),
110113
File.join(root_directory, SERIALIZERS_SPEC_DIR, "%MODEL_NAME%_serializer_spec.rb")
111114
]
115+
when 'controller'
116+
[
117+
File.join(root_directory, CONTROLLER_DIR, "%PLURALIZED_MODEL_NAME%_controller.rb")
118+
]
112119
end
113120
end
114121
end
@@ -376,6 +383,7 @@ def remove_annotation_of_file(file_name)
376383
# :exclude_factories<Symbol>:: whether to skip modification of factory files
377384
# :exclude_serializers<Symbol>:: whether to skip modification of serializer files
378385
# :exclude_scaffolds<Symbol>:: whether to skip modification of scaffold files
386+
# :exclude_controllers<Symbol>:: whether to skip modification of controller files
379387
#
380388
def annotate(klass, file, header, options={})
381389
begin
@@ -389,7 +397,7 @@ def annotate(klass, file, header, options={})
389397
did_annotate = true
390398
end
391399

392-
%w(test fixture factory serializer scaffold).each do |key|
400+
%w(test fixture factory serializer scaffold controller).each do |key|
393401
exclusion_key = "exclude_#{key.pluralize}".to_sym
394402
patterns_type = "#{key.downcase}"
395403
position_key = "position_in_#{key}".to_sym
@@ -544,7 +552,7 @@ def remove_annotations(options={})
544552
model_file_name = file
545553
deannotated_klass = true if(remove_annotation_of_file(model_file_name))
546554

547-
(get_patterns(%w[test scaffold fixture factory serializer])).
555+
(get_patterns(%w[test scaffold fixture factory serializer controller])).
548556
map { |file| resolve_filename(file, model_name, table_name) }.
549557
each do |file|
550558
if File.exist?(file)

lib/generators/annotate/templates/auto_annotate_models.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ if Rails.env.development?
2424
'exclude_factories' => 'false',
2525
'exclude_serializers' => 'false',
2626
'exclude_scaffolds' => 'false',
27+
'exclude_controllers' => 'true',
2728
'ignore_model_sub_dir' => 'false',
2829
'skip_on_db_migrate' => 'false',
2930
'format_bare' => 'true',

lib/tasks/annotate_models.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ task :annotate_models => :environment do
2929
options[:exclude_fixtures] = Annotate.true?(ENV['exclude_fixtures'])
3030
options[:exclude_serializers] = Annotate.true?(ENV['exclude_serializers'])
3131
options[:exclude_scaffolds] = Annotate.true?(ENV['exclude_scaffolds'])
32+
options[:exclude_controllers] = Annotate.true?(ENV['exclude_controllers'])
3233
options[:ignore_model_sub_dir] = Annotate.true?(ENV['ignore_model_sub_dir'])
3334
options[:format_bare] = Annotate.true?(ENV['format_bare'])
3435
options[:format_rdoc] = Annotate.true?(ENV['format_rdoc'])

0 commit comments

Comments
 (0)