Class: ValidationScopes::AssociatedValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validation_scopes.rb

Overview

Based on AssociatedValidator from ActiveRecord, see: activerecord-4.2.0/lib/active_record/validations/associated.rb @ line 3

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/validation_scopes.rb', line 12

def validate_each(record, attribute, value)
  all_valid = Array.wrap(value).all? do |r|
    r.marked_for_destruction? || r.send("no_#{options[:scope]}?")
  end
  unless all_valid
    record.errors.add(attribute, 'is invalid')
  end
end