Module: UnicodeTools::ActiveRecordExtension::Squish

Defined in:
lib/unicode-tools/active_record_extension/squish.rb

Instance Method Summary collapse

Instance Method Details

#squish(*attributes) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/unicode-tools/active_record_extension/squish.rb', line 7

def squish(*attributes)
  extension = Module.new

  attributes.each do |attribute|
    extension.class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{attribute}=(value)
        super(String === value ? value.squish.presence : value)
      end
    RUBY
  end

  include extension

  nil
end