Class: ActiveModel::Validations::StoreModelValidator

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

Overview

StoreModelValidator is a subclass of ActiveModel::EachValidator for checking StoreModel::Model attributes.

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

Validates json attribute using the configured strategy or invalidates array attribute when at least one element is invalid.

Parameters:

  • record (ApplicationRecord)

    object to validate

  • attribute (String)

    name of the validated attribute

  • value (Object)

    value of the validated attribute



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_model/validations/store_model_validator.rb', line 17

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, :polymorphic
    call_json_strategy(record, attribute, value)
  when :array, :polymorphic_array
    call_array_strategy(record, attribute, value)
  end
end