couchrest_model/lib/couchrest/model/validations/casted_model.rb

15 lines
447 B
Ruby
Raw Normal View History

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?
document.errors.add(attribute, :invalid, :message => options[:message], :value => value)
end
end
end
end
end