Class: ActiveModel::Validations::GrandparentValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::GrandparentValidator
- Defined in:
- lib/can_has_validations/validators/grandparent_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, association) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/can_has_validations/validators/grandparent_validator.rb', line 9 def validate_each(record, attribute, association) all_match = Array([:scope]).all? do |scope| cousin = record.send(scope) if cousin.nil? [:allow_nil] else association.send([:parent]) == cousin.send([:parent]) end end unless all_match record.errors.add(attribute, :invalid, .except(:allow_nil, :parent, :scope)) end end |