Class: CouchRest::Model::Validations::CastedModelValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/couchrest/model/validations/casted_model.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(document, attribute, value) ⇒ Object



6
7
8
9
10
# File 'lib/couchrest/model/validations/casted_model.rb', line 6

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, :default => options[:message], :value => value)
end