Sha256: b943dbd073a323e8a61a0538e48eaa9ac1e8d6a080deb3393c396c8e71637fd8
Contents?: true
Size: 1.18 KB
Versions: 52
Compression:
Stored size: 1.18 KB
Contents
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 TestTypesValidator < ActiveModel::Validator def validate(record) for field in options[:fields] value = record.attributes[field] valid = value.is_a?(String) and value.split(",").is_a?(Array) rescue false record.errors.add(field, "#{field} must be a comma delimited string of one of more test id's' like so: \"test_type1\" or \"test_type1, test_type2\" ") unless valid end end end # A valid date for the orders is a little different that usual .. so take note '%Y%m%d' # has no slashes or dashes .. so a date is valid that looks like: '20111202' 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
Version data entries
52 entries across 52 versions & 1 rubygems