Module: TrimSpacesFor::ActiveRecordExtension::ClassMethods

Defined in:
lib/trim_spaces_for/active_record_extension.rb

Instance Method Summary collapse

Instance Method Details

#trim_spaces_for(*target_attributes) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/trim_spaces_for/active_record_extension.rb', line 8

def trim_spaces_for(*target_attributes)
  before_validation do |model|
    target_attributes.each do |attribute|
      before_cast = model.__send__("#{attribute}_before_type_cast")
      if before_cast.respond_to?(:trim_white_spaces)
        model.__send__("#{attribute}=", before_cast.trim_white_spaces)
      end
    end
  end
end