Class: LinkedVocabs::Validators::PropertyValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/linked_vocabs/validators/property_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, values) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/linked_vocabs/validators/property_validator.rb', line 5

def validate_each(record, attribute, values)
  values.each do |v|
    unless v.try(:in_vocab?)
      term = v.try(:rdf_subject) || v
      vocabularies = record.class.properties[attribute].class_name.vocabularies.keys
      record.errors.add :base, "value `#{term} for `#{attribute}` property is not a term in a controlled vocabulary #{vocabularies.join(', ')}"
    end
  end
end