Skip to content

Annotate controllers and helpers #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/annotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Annotate
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
:timestamp, :exclude_serializers, :classified_sort, :show_foreign_keys,
:exclude_scaffolds
:exclude_scaffolds, :exclude_controllers, :exclude_helpers
]
OTHER_OPTIONS=[
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :wrapper
Expand Down
18 changes: 17 additions & 1 deletion lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module AnnotateModels
END_MARK = "== Schema Information End"
PATTERN = /^\r?\n?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?\r?\n(#.*\r?\n)*(\r?\n)*/

MATCHED_TYPES = %w(test fixture factory serializer scaffold)
MATCHED_TYPES = %w(test fixture factory serializer scaffold controller helper)

# File.join for windows reverse bar compat?
# I dont use windows, can`t test
Expand Down Expand Up @@ -46,6 +46,12 @@ module AnnotateModels
SERIALIZERS_TEST_DIR = File.join("test", "serializers")
SERIALIZERS_SPEC_DIR = File.join("spec", "serializers")

# Controller files
CONTROLLER_DIR = File.join("app", "controllers")

# Helper files
HELPER_DIR = File.join("app", "helpers")

# Don't show limit (#) on these column types
# Example: show "integer" instead of "integer(4)"
NO_LIMIT_COL_TYPES = ["integer", "boolean"]
Expand Down Expand Up @@ -111,6 +117,14 @@ def get_patterns(pattern_types=MATCHED_TYPES)
File.join(root_directory, SERIALIZERS_TEST_DIR, "%MODEL_NAME%_serializer_spec.rb"),
File.join(root_directory, SERIALIZERS_SPEC_DIR, "%MODEL_NAME%_serializer_spec.rb")
]
when 'controller'
[
File.join(root_directory, CONTROLLER_DIR, "%PLURALIZED_MODEL_NAME%_controller.rb")
]
when 'helper'
[
File.join(root_directory, HELPER_DIR, "%PLURALIZED_MODEL_NAME%_helper.rb")
]
end
end
end
Expand Down Expand Up @@ -381,6 +395,8 @@ def remove_annotation_of_file(file_name)
# :exclude_factories<Symbol>:: whether to skip modification of factory files
# :exclude_serializers<Symbol>:: whether to skip modification of serializer files
# :exclude_scaffolds<Symbol>:: whether to skip modification of scaffold files
# :exclude_controllers<Symbol>:: whether to skip modification of controller files
# :exclude_helpers<Symbol>:: whether to skip modification of helper files
#
def annotate(klass, file, header, options={})
begin
Expand Down
2 changes: 2 additions & 0 deletions lib/generators/annotate/templates/auto_annotate_models.rake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ if Rails.env.development?
'exclude_factories' => 'false',
'exclude_serializers' => 'false',
'exclude_scaffolds' => 'false',
'exclude_controllers' => 'false',
'exclude_helpers' => 'false',
'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil,
'skip_on_db_migrate' => 'false',
Expand Down
2 changes: 2 additions & 0 deletions lib/tasks/annotate_models.rake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ task :annotate_models => :environment do
options[:exclude_fixtures] = Annotate.true?(ENV['exclude_fixtures'])
options[:exclude_serializers] = Annotate.true?(ENV['exclude_serializers'])
options[:exclude_scaffolds] = Annotate.true?(ENV['exclude_scaffolds'])
options[:exclude_controllers] = Annotate.true?(ENV['exclude_controllers'])
options[:exclude_helpers] = Annotate.true?(ENV['exclude_helpers'])
options[:ignore_model_sub_dir] = Annotate.true?(ENV['ignore_model_sub_dir'])
options[:format_bare] = Annotate.true?(ENV['format_bare'])
options[:format_rdoc] = Annotate.true?(ENV['format_rdoc'])
Expand Down