From 22454d750a212fd24c0f48f77e95a61c8814fb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20S=C3=A5gfors?= Date: Thu, 2 Mar 2017 14:35:24 +0200 Subject: [PATCH 1/3] Prevent root_dir option from being empty When setting root_dir to an empty string (as is done in the default rake task config) this line previously caused root_dir to become an empty array. This in turn caused factories, specs etc not to be annotated. This is just a quick band-aid on a larger problem. We have option parsing spread out over many different places, with slight mismatches like this in the assumptions made. --- lib/tasks/annotate_models.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/annotate_models.rake b/lib/tasks/annotate_models.rake index e958bdaab..437b35c02 100644 --- a/lib/tasks/annotate_models.rake +++ b/lib/tasks/annotate_models.rake @@ -21,7 +21,7 @@ task annotate_models: :environment do options[:show_indexes] = Annotate.true?(ENV['show_indexes']) options[:simple_indexes] = Annotate.true?(ENV['simple_indexes']) options[:model_dir] = ENV['model_dir'] ? ENV['model_dir'].split(',') : ['app/models'] - options[:root_dir] = ENV['root_dir'] ? ENV['root_dir'].split(',') : [''] + options[:root_dir] = ENV['root_dir'] && !ENV['root_dir'].empty? ? ENV['root_dir'].split(',') : [''] options[:include_version] = Annotate.true?(ENV['include_version']) options[:require] = ENV['require'] ? ENV['require'].split(',') : [] options[:exclude_tests] = Annotate.true?(ENV['exclude_tests']) From 82f2d4d59b0f9e27df2d53d29de27d328c3c5b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20S=C3=A5gfors?= Date: Sun, 5 Mar 2017 00:27:25 +0200 Subject: [PATCH 2/3] Handle blank values & comma-separated strings in AnnotateModels.root_dir These cases are currently handled (inconsistently) in the different option parsing routines. --- lib/annotate/annotate_models.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index b91eb280f..9704f5bed 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -80,7 +80,13 @@ def model_dir attr_writer :model_dir def root_dir - @root_dir.is_a?(Array) ? @root_dir : [@root_dir || ''] + if @root_dir.blank? + [''] + elsif @root_dir.is_a?(String) + @root_dir.split(',') + else + @root_dir + end end attr_writer :root_dir From 01a5c41684de769653fe353fd2af5b562a1b8a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20S=C3=A5gfors?= Date: Sun, 5 Mar 2017 00:29:11 +0200 Subject: [PATCH 3/3] Pass root_dir forward unmodified The different cases are now handled inside AnnotateModels --- lib/annotate.rb | 1 - lib/tasks/annotate_models.rake | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/annotate.rb b/lib/annotate.rb index 96a7b4698..a17b14215 100755 --- a/lib/annotate.rb +++ b/lib/annotate.rb @@ -88,7 +88,6 @@ def self.setup_options(options = {}) end options[:model_dir] = ['app/models'] if options[:model_dir].empty? - options[:root_dir] = [''] if options[:root_dir].empty? options[:wrapper_open] ||= options[:wrapper] options[:wrapper_close] ||= options[:wrapper] diff --git a/lib/tasks/annotate_models.rake b/lib/tasks/annotate_models.rake index 437b35c02..e128a752a 100644 --- a/lib/tasks/annotate_models.rake +++ b/lib/tasks/annotate_models.rake @@ -21,7 +21,7 @@ task annotate_models: :environment do options[:show_indexes] = Annotate.true?(ENV['show_indexes']) options[:simple_indexes] = Annotate.true?(ENV['simple_indexes']) options[:model_dir] = ENV['model_dir'] ? ENV['model_dir'].split(',') : ['app/models'] - options[:root_dir] = ENV['root_dir'] && !ENV['root_dir'].empty? ? ENV['root_dir'].split(',') : [''] + options[:root_dir] = ENV['root_dir'] options[:include_version] = Annotate.true?(ENV['include_version']) options[:require] = ENV['require'] ? ENV['require'].split(',') : [] options[:exclude_tests] = Annotate.true?(ENV['exclude_tests'])