Sha256: 9b4d3f752026a0696d5e80b191eeb2251e94f34ae83da9c45c1d89383e5173ab

Contents?: true

Size: 575 Bytes

Versions: 1

Compression:

Stored size: 575 Bytes

Contents

# encoding: UTF-8
# frozen_string_literal: true

module Autostrip
  module Extension
    def autostrip(*attributes)
      attributes.each do |attribute|
        # Use prepend to be sure this runs before all other "before_validation" callbacks.
        before_validation prepend: true do |model|
          value = model.send(attribute)
          if Autostrip.performable?(value)
            # http://www.davidverhasselt.com/set-attributes-in-activerecord/
            model.send("#{attribute}=", Autostrip.perform(value))
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
autostrip-1.0.3 lib/autostrip/extension.rb