Class: ActiveRecord::Attr::Stripper::AttrStripper

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord/attr/stripper/attr_stripper.rb

Instance Method Summary collapse

Instance Method Details

#before_validation(record) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/activerecord/attr/stripper/attr_stripper.rb', line 10

def before_validation(record)
  strip_targets = record.class.class_variable_get :@@strip_targets

  return if strip_targets.blank?

  strip_targets.each do |target|
    target.attrs.each do |attr|
      attr_value = record.send(attr)

      if attr_value.kind_of?(String)
        stripped_value = strip(attr_value, target.opts)

        record.send("#{attr.to_s}=", stripped_value)
      end
    end
  end
end