Commit 31fe4c5a by cuong.tran

Do not annotate controllers, helpers and scaffolds by default (revert to…

Do not annotate controllers, helpers and scaffolds by default (revert to behavior from previous version)
parent 64b1a343
......@@ -14,6 +14,8 @@ rescue Exception
end
module Annotate
TRUE_RE = /^(true|t|yes|y|1)$/i
##
# The set of available options to customize the behavior of Annotate.
#
......@@ -60,7 +62,9 @@ module Annotate
end
end
TRUE_RE = /^(true|t|yes|y|1)$/i
##
# TODO: what is the difference between this and set_defaults?
#
def self.setup_options(options = {})
POSITION_OPTIONS.each do |key|
options[key] = fallback(ENV[key.to_s], ENV['position'], 'before')
......@@ -86,6 +90,11 @@ module Annotate
options[:wrapper_open] ||= options[:wrapper]
options[:wrapper_close] ||= options[:wrapper]
# These were added in 2.7.0 but so this is to revert to old behavior by default
options[:exclude_scaffolds] = Annotate.true?(ENV.fetch('exclude_scaffolds', 'true'))
options[:exclude_controllers] = Annotate.true?(ENV.fetch('exclude_controllers', 'true'))
options[:exclude_helpers] = Annotate.true?(ENV.fetch('exclude_helpers', 'true'))
return options
end
......
......@@ -320,7 +320,9 @@ module AnnotateModels
# a schema info block (a comment starting with "== Schema Information"), check if it
# matches the block that is already there. If so, leave it be. If not, remove the old
# info block and write a new one.
# Returns true or false depending on whether the file was modified.
#
# == Returns:
# true or false depending on whether the file was modified.
#
# === Options (opts)
# :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
......@@ -394,8 +396,6 @@ module AnnotateModels
# info block (basically a comment containing information
# on the columns and their types) and put it at the front
# of the model and fixture source files.
# Returns true or false depending on whether the source
# files were modified.
#
# === Options (opts)
# :position_in_class<Symbol>:: where to place the annotated section in model file
......@@ -411,16 +411,19 @@ module AnnotateModels
# :exclude_controllers<Symbol>:: whether to skip modification of controller files
# :exclude_helpers<Symbol>:: whether to skip modification of helper files
#
# == Returns:
# an array of file names that were annotated.
#
def annotate(klass, file, header, options={})
begin
info = get_schema_info(klass, header, options)
did_annotate = false
model_name = klass.name.underscore
table_name = klass.table_name
model_file_name = File.join(file)
annotated = []
if annotate_one_file(model_file_name, info, :position_in_class, options_with_position(options, :position_in_class))
did_annotate = true
annotated << model_file_name
end
MATCHED_TYPES.each do |key|
......@@ -428,18 +431,21 @@ module AnnotateModels
position_key = "position_in_#{key}".to_sym
unless options[exclusion_key]
did_annotate = self.get_patterns(key).
self.get_patterns(key).
map { |f| resolve_filename(f, model_name, table_name) }.
map { |f| annotate_one_file(f, info, position_key, options_with_position(options, position_key)) }.
detect { |result| result } || did_annotate
each { |f|
if annotate_one_file(f, info, position_key, options_with_position(options, position_key))
annotated << f
end
}
end
end
return did_annotate
rescue Exception => e
puts "Unable to annotate #{file}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end
return annotated
end
# position = :position_in_fixture or :position_in_class
......@@ -537,9 +543,10 @@ module AnnotateModels
self.root_dir = options[:root_dir] if options[:root_dir]
annotated = []
get_model_files(options).each do |file|
annotate_model_file(annotated, File.join(file), header, options)
get_model_files(options).each do |path, filename|
annotate_model_file(annotated, File.join(path, filename), header, options)
end
if annotated.empty?
puts "Model files unchanged."
else
......@@ -552,9 +559,7 @@ module AnnotateModels
return false if (/# -\*- SkipSchemaAnnotations.*/ =~ (File.exist?(file) ? File.read(file) : '') )
klass = get_model_class(file)
if klass && klass < ActiveRecord::Base && !klass.abstract_class? && klass.table_exists?
if annotate(klass, file, header, options)
annotated << file
end
annotated.concat(annotate(klass, file, header, options))
end
rescue BadModelFileError => e
unless options[:ignore_unknown_models]
......
......@@ -24,9 +24,9 @@ if Rails.env.development?
'exclude_fixtures' => 'false',
'exclude_factories' => 'false',
'exclude_serializers' => 'false',
'exclude_scaffolds' => 'false',
'exclude_controllers' => 'false',
'exclude_helpers' => 'false',
'exclude_scaffolds' => 'true',
'exclude_controllers' => 'true',
'exclude_helpers' => 'true',
'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil,
'ignore_routes' => nil,
......
......@@ -29,8 +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[:exclude_controllers] = Annotate.true?(ENV.fetch('exclude_controllers', 'true'))
options[:exclude_helpers] = Annotate.true?(ENV.fetch('exclude_helpers', 'true'))
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'])
......
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