Class: ActiveModel::Validations::StoreModelValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/active_model/validations/store_model_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_model/validations/store_model_validator.rb', line 9

def validate_each(record, attribute, value)
  if value.nil?
    record.errors.add(attribute, :blank)
    return
  end

  case record.type_for_attribute(attribute).type
  when :json
    strategy.call(attribute, record.errors, value.errors) if value.invalid?
  when :array
    record.errors.add(attribute, :invalid) if value.any?(&:invalid?)
  end
end