Skip to content

Commit

Permalink
Prevent root_dir option from being empty (#448)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lime authored and ctran committed Mar 5, 2017
1 parent 82a2c40 commit 8341983
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/annotate.rb
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion lib/annotate/annotate_models.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/annotate_models.rake
Expand Up @@ -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']
options[:include_version] = Annotate.true?(ENV['include_version'])
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
options[:exclude_tests] = Annotate.true?(ENV['exclude_tests'])
Expand Down

0 comments on commit 8341983

Please sign in to comment.