2010-06-20 22:01:11 +02:00
|
|
|
module CouchRest
|
|
|
|
module Model
|
|
|
|
module Validations
|
|
|
|
class CastedModelValidator < ActiveModel::EachValidator
|
|
|
|
|
|
|
|
def validate_each(document, attribute, value)
|
|
|
|
values = value.is_a?(Array) ? value : [value]
|
|
|
|
return if values.collect {|doc| doc.nil? || doc.valid? }.all?
|
2010-12-28 21:24:59 +01:00
|
|
|
error_options = { :value => value }
|
|
|
|
error_options[:message] = options[:message] if options[:message]
|
|
|
|
document.errors.add(attribute, :invalid, error_options)
|
2010-06-20 22:01:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|