4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/acts_as_scrubbable/scrub.rb', line 4
def scrub!
if self.class.scrubbable?
_updates = {}
scrubbable_fields.each do |_field, value|
unless self.respond_to?(_field)
raise ArgumentError, "#{self.class} do not respond to #{_field}"
end
next if self.send(_field).blank?
if ActsAsScrubbable.scrub_map.keys.include?(value)
_updates[_field] = ActsAsScrubbable.scrub_map[value].call
else
puts "Undefined scrub: #{value} for #{self.class}#{_field}"
end
end
self.update_columns(_updates) unless _updates.empty?
end
end
|