Class: NestedValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/couchbase-orm/types/nested.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/couchbase-orm/types/nested.rb', line 4

def validate_each(record, attribute, value)
  if value.is_a?(Array)
    record.errors.add attribute, (options[:message] || 'is invalid') unless value.map(&:valid?).all?
  else
    record.errors.add attribute, (options[:message] || 'is invalid') unless
value.nil? || value.valid?
  end
end