Method: PassthruValidator#validate_each
- Defined in:
- app/validators/passthru_validator.rb
#validate_each(record, attribute, value) ⇒ Object
record - Form object (e.g. Decidim::UploadValidationForm) attribute - The attribute to validate (e.g. :avatar) value - Blob’s signed id (e.g. “eyJfcmFpbHMi…”)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/validators/passthru_validator.rb', line 24 def validate_each(record, attribute, value) return unless target_class dummy_attr = target_attribute(attribute) # Create a dummy record for which the validations are actually run on dummy = validation_record(record) if dummy.respond_to?(dummy_attr) && !(value.class <= ActiveStorage::Attached) dummy.public_send("#{dummy_attr}=", value) value = dummy.public_send(dummy_attr) elsif dummy.respond_to? :file dummy.public_send("file=", value) value = dummy.public_send(:file) end target_validators(attribute).each do |validator| next unless validator.is_a?(ActiveModel::EachValidator) next unless check_validator_conditions(dummy, validator) dummy.errors.clear validator.validate_each(dummy, dummy_attr, value) dummy.errors[dummy_attr].each do |err| record.errors.add(attribute, err) end end end |