class DocumentValidator
Public Instance Methods
validate_each(record, attribute, values)
click to toggle source
# File lib/thingtank/validators.rb, line 90 def validate_each(record, attribute, values) case values when NilClass return nil when Array values.each do |value| validate_single_doc(record, attribute, value, options) end else validate_single_doc(record, attribute, values, options) end end
validate_single_doc(record, attribute, value, options)
click to toggle source
# 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