Class: Medivo::TestTypesValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/support/validators.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/support/validators.rb', line 12

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