Class: ValidityValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ValidityValidator
- Defined in:
- lib/tram/validators/validity_validator.rb
Overview
Checks that value of some attribute is valid per se Otherwise populates the record with the attribute’s validation errors
With option ‘original_keys: true` it copies value’s errors to the record under their original keys, as if the [#record] had attributes of the [#value]. Otherwise the errors are copied under the [#attribute] key.
This is necessary for validation of the form models, as well as other decorated objects.
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tram/validators/validity_validator.rb', line 15 def validate_each(record, attribute, value) if !value.respond_to? :invalid? record.errors.add attribute, :invalidable, record: record, attribute: attribute, value: value elsif value.invalid? value.errors..each do |key, | error_key = Tram::Validators.error_key(key, attribute, ) .each { || record.errors.add error_key, } end end end |