Skip to content

Commit 8341983

Browse files
limectran
authored andcommitted
Prevent root_dir option from being empty (#448)
* 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. * Handle blank values & comma-separated strings in AnnotateModels.root_dir These cases are currently handled (inconsistently) in the different option parsing routines. * Pass root_dir forward unmodified The different cases are now handled inside AnnotateModels
1 parent 82a2c40 commit 8341983

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/annotate.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def self.setup_options(options = {})
8888
end
8989

9090
options[:model_dir] = ['app/models'] if options[:model_dir].empty?
91-
options[:root_dir] = [''] if options[:root_dir].empty?
9291

9392
options[:wrapper_open] ||= options[:wrapper]
9493
options[:wrapper_close] ||= options[:wrapper]

lib/annotate/annotate_models.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ def model_dir
8080
attr_writer :model_dir
8181

8282
def root_dir
83-
@root_dir.is_a?(Array) ? @root_dir : [@root_dir || '']
83+
if @root_dir.blank?
84+
['']
85+
elsif @root_dir.is_a?(String)
86+
@root_dir.split(',')
87+
else
88+
@root_dir
89+
end
8490
end
8591

8692
attr_writer :root_dir

lib/tasks/annotate_models.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ task annotate_models: :environment do
2121
options[:show_indexes] = Annotate.true?(ENV['show_indexes'])
2222
options[:simple_indexes] = Annotate.true?(ENV['simple_indexes'])
2323
options[:model_dir] = ENV['model_dir'] ? ENV['model_dir'].split(',') : ['app/models']
24-
options[:root_dir] = ENV['root_dir'] ? ENV['root_dir'].split(',') : ['']
24+
options[:root_dir] = ENV['root_dir']
2525
options[:include_version] = Annotate.true?(ENV['include_version'])
2626
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
2727
options[:exclude_tests] = Annotate.true?(ENV['exclude_tests'])

0 commit comments

Comments
 (0)