module Medivo class ArrayValidator < ActiveModel::Validator def validate(record) for field in options[:fields] value = record.attributes[field] record.errors.add(field, "#{field} must be an array") unless value.is_a? Array end end end class DateValidator < ActiveModel::Validator def validate(record) for field in options[:fields] value = record.attributes[field] date = Date.strptime(value, '%Y%m%d') rescue nil record.errors.add(field, "invalid #{field}. needs to be in '%Y%m%d' format") unless date end end end end