Skip to content

Commit 5685185

Browse files
committed
Fix ignore_columns option in auto_annotate_models task
1 parent d9623df commit 5685185

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

lib/annotate.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,26 @@ module Annotate
3636
:require, :model_dir
3737
]
3838

39-
4039
##
4140
# Set default values that can be overridden via environment variables.
4241
#
4342
def self.set_defaults(options = {})
4443
return if(@has_set_defaults)
4544
@has_set_defaults = true
45+
4646
options = HashWithIndifferentAccess.new(options)
47+
4748
[POSITION_OPTIONS, FLAG_OPTIONS, PATH_OPTIONS, OTHER_OPTIONS].flatten.each do |key|
48-
if(options.has_key?(key))
49-
default_value = if(options[key].is_a?(Array))
49+
if options.has_key?(key)
50+
default_value = if options[key].is_a?(Array)
5051
options[key].join(",")
5152
else
5253
options[key]
5354
end
5455
end
55-
default_value = ENV[key.to_s] if(!ENV[key.to_s].blank?)
56-
ENV[key.to_s] = default_value.to_s
56+
57+
default_value = ENV[key.to_s] if !ENV[key.to_s].blank?
58+
ENV[key.to_s] = default_value.nil? ? nil : default_value.to_s
5759
end
5860
end
5961

lib/annotate/annotate_models.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ def get_schema_info(klass, header, options = {})
143143
info<< "# #{ '-' * ( max_size + md_names_overhead ) } | #{'-' * md_type_allowance} | #{ '-' * 27 }\n"
144144
end
145145

146-
cols = klass.columns.dup
147-
if options[:ignore_columns]
148-
cols.reject! { |col| col.name.match(/#{options[:ignore_columns]}/) }
149-
end
146+
cols = if ignore_columns = options[:ignore_columns]
147+
klass.columns.reject do |col|
148+
col.name.match(/#{ignore_columns}/)
149+
end
150+
else
151+
klass.columns
152+
end
150153

151154
cols = cols.sort_by(&:name) if(options[:sort])
152155
cols = classified_sort(cols) if(options[:classified_sort])

lib/generators/annotate/templates/auto_annotate_models.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ if Rails.env.development?
2424
'exclude_serializers' => 'false',
2525
'exclude_scaffolds' => 'false',
2626
'ignore_model_sub_dir' => 'false',
27+
'ignore_columns' => nil,
2728
'skip_on_db_migrate' => 'false',
2829
'format_bare' => 'true',
2930
'format_rdoc' => 'false',

lib/tasks/annotate_models.rake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
annotate_lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
22

3-
if(!ENV['is_cli'])
3+
if !ENV['is_cli']
44
task :set_annotation_options
55
task :annotate_models => :set_annotation_options
66
end
@@ -38,7 +38,8 @@ task :annotate_models => :environment do
3838
options[:trace] = Annotate.true?(ENV['trace'])
3939
options[:wrapper_open] = Annotate.fallback(ENV['wrapper_open'], ENV['wrapper'])
4040
options[:wrapper_close] = Annotate.fallback(ENV['wrapper_close'], ENV['wrapper'])
41-
options[:ignore_columns] = ENV['ignore_columns']
41+
options[:ignore_columns] = ENV.fetch('ignore_columns', nil)
42+
4243
AnnotateModels.do_annotations(options)
4344
end
4445

0 commit comments

Comments
 (0)