Skip to content

Commit 7325e3c

Browse files
committed
Merge pull request #298 from wouterw/ww-fix-ignore-columns
Fix :ignore_columns option in "auto_annotate_models" task
2 parents b53cc93 + 5685185 commit 7325e3c

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, :root_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
@@ -163,10 +163,13 @@ def get_schema_info(klass, header, options = {})
163163
info<< "# #{ '-' * ( max_size + md_names_overhead ) } | #{'-' * md_type_allowance} | #{ '-' * 27 }\n"
164164
end
165165

166-
cols = klass.columns.dup
167-
if options[:ignore_columns]
168-
cols.reject! { |col| col.name.match(/#{options[:ignore_columns]}/) }
169-
end
166+
cols = if ignore_columns = options[:ignore_columns]
167+
klass.columns.reject do |col|
168+
col.name.match(/#{ignore_columns}/)
169+
end
170+
else
171+
klass.columns
172+
end
170173

171174
cols = cols.sort_by(&:name) if(options[:sort])
172175
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
@@ -25,6 +25,7 @@ if Rails.env.development?
2525
'exclude_serializers' => 'false',
2626
'exclude_scaffolds' => 'false',
2727
'ignore_model_sub_dir' => 'false',
28+
'ignore_columns' => nil,
2829
'skip_on_db_migrate' => 'false',
2930
'format_bare' => 'true',
3031
'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
@@ -39,7 +39,8 @@ task :annotate_models => :environment do
3939
options[:trace] = Annotate.true?(ENV['trace'])
4040
options[:wrapper_open] = Annotate.fallback(ENV['wrapper_open'], ENV['wrapper'])
4141
options[:wrapper_close] = Annotate.fallback(ENV['wrapper_close'], ENV['wrapper'])
42-
options[:ignore_columns] = ENV['ignore_columns']
42+
options[:ignore_columns] = ENV.fetch('ignore_columns', nil)
43+
4344
AnnotateModels.do_annotations(options)
4445
end
4546

0 commit comments

Comments
 (0)