require 'dm-core' module DataMapper module Trimmer def self.included(base) base.class_eval do alias_method :set_without_trimmer!, :set! alias_method :set!, :set_with_trimmer! end end def set_with_trimmer!(name, value) value = value.strip if value.respond_to?(:strip) value = nil if value.respond_to?(:empty?) && value.empty? set_without_trimmer!(name, value) end end Property.send(:include, Trimmer) end