module PowerTools module ActiveRecord EMAIL_FORMAT = /^([^@\s]+)@((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})$/ US_ZIP_FORMAT = /^\d{5}([\-]\d{4})?$/ US_STATE_FORMAT = /^[a-zA-Z]{2}$/ US_TEL_FORMAT = /^[0-9]{10}$/ def self.included(base) base.extend(ClassMethods) end module ClassMethods def validates_email(*attr_names) options = { :with => EMAIL_FORMAT } options.update(attr_names.pop) if attr_names.last.is_a?(Hash) attr_names.push(options) validates_format_of *attr_names end def all(*args) find :all, *args end def [](id) find id end def first(*args) find :first, *args end def last(*args) find(:all, *args)[-1] end end end end ActiveRecord::Base.class_eval do include PowerTools::ActiveRecord include PowerTools::ActiveRecord::AccountStamp include PowerTools::ActiveRecord::Serialization extend PowerTools::ActiveRecord::SetAssociationWithHash end