22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/strip_attributes.rb', line 22
def strip_attributes!
return if strip_attributes_options.nil?
self.class.columns.each do |column|
next unless (column.type == :string || column.type == :text)
field = column.name.to_sym
value = self[field]
if !value.respond_to?(:strip)
next
elsif strip_attributes_options[:except].include?(field)
next
elsif strip_attributes_options[:only].any? && !strip_attributes_options[:only].include?(field)
next
else
self[field] = (value.blank?) ? nil : value.strip
end
end
end
|