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

- (Object) validate_each(document, attribute, value)



6
7
8
9
10
11
12
# 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?
  error_options = { :value => value }
  error_options[:message] = options[:message] if options[:message]
  document.errors.add(attribute, :invalid, error_options)
end