class ActiveModel::Validations::StoreModelValidator
StoreModelValidator
is a subclass of ActiveModel::EachValidator for checking StoreModel::Model
attributes.
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
Validates json attribute using the configured strategy or invalidates array attribute when at least one element is invalid.
@param record [ApplicationRecord] object to validate @param attribute [String] name of the validated attribute @param value [Object] value of the validated attribute
# 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(attribute, record.errors, value) when :array, :polymorphic_array call_array_strategy(attribute, record.errors, value) end end
Private Instance Methods
array_strategy()
click to toggle source
# File lib/active_model/validations/store_model_validator.rb, line 45 def array_strategy @array_strategy ||= StoreModel::CombineErrorsStrategies.configure_array(options) end
call_array_strategy(attribute, record_errors, value)
click to toggle source
# File lib/active_model/validations/store_model_validator.rb, line 37 def call_array_strategy(attribute, record_errors, value) array_strategy.call(attribute, record_errors, value) if value.select(&:invalid?).present? end
call_json_strategy(attribute, record_errors, value)
click to toggle source
# File lib/active_model/validations/store_model_validator.rb, line 33 def call_json_strategy(attribute, record_errors, value) strategy.call(attribute, record_errors, value.errors) if value.invalid? end
strategy()
click to toggle source
# File lib/active_model/validations/store_model_validator.rb, line 41 def strategy @strategy ||= StoreModel::CombineErrorsStrategies.configure(options) end