Class: ActiveModel::Validations::SkitValidator

Inherits:
EachValidator
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/active_model/validations/skit_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_model/validations/skit_validator.rb', line 10

def validate_each(record, attribute, value)
  return if value.nil?

  attribute_type = get_skit_attribute_type(record, attribute)
  return unless attribute_type

  processor = attribute_type.processor
  processor.traverse(value) do |_type_spec, node, path|
    next unless node.respond_to?(:valid?)
    next if node.valid?

    node.errors.each do |error|
      error_key = build_error_key(attribute, path, error.attribute)
      record.errors.add(error_key, error.message)
    end
  end
end