module DrNicMagicModels module Validations def self.append_features(base) super base.extend(ClassMethods) base.generate_validations # Currently only invoked on generated classes # How to include and invoke on all ARs? - hook into class loading?? end module ClassMethods def generate_validations unless @@generated_validations ||= false @@generated_validations = true column_names = self.columns.select {|column| !column.null and !column.primary}.map {|column| column.name.to_sym} add_validation :validates_presence_of, column_names end end def add_validation(validation, column_names) self.send validation, *column_names end end end end