Method: DocumentValidator#validate_single_doc

Defined in:
lib/thingtank/validators.rb

#validate_single_doc(record, attribute, value, options) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/thingtank/validators.rb', line 78

def validate_single_doc(record, attribute, value, options)
  if options[:inline]
    return record.errors.add attribute, "#{value.inspect} should be an inlined doc that is converted to a hash" unless value.is_a? Hash
    record.errors.add attribute, character.errors.messages unless ThingTank.new(value).valid?
  else
    match = (value =~ /^\!\#(.+)$/)
    doc_id = $1
    return record.errors.add attribute, "#{value.inspect} does not begin with !# and is therefor no doc id" unless match      
    record.errors.add attribute, "doc with id #{doc_id} does not exist" unless record._doc.class.get(doc_id)
  end
end