Method: ActiveJsonModel::Array#active_json_model_validate
- Defined in:
- lib/active_json_model/array.rb
#active_json_model_validate ⇒ Object
Validate method that handles recursive validation into models in the array. Individual validations on attributes for this model will be handled by the standard mechanism.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/active_json_model/array.rb', line 195 def active_json_model_validate errors.add(:values, 'ActiveJsonModel::Array values must be an array') unless values.is_a?(::Array) values.each_with_index do |val, i| # Check if attribute value is an ActiveJsonModel if val && val.respond_to?(:valid?) # This call to <code>valid?</code> is important because it will actually trigger recursive validations unless val.valid? val.errors.each do |error| errors.add("[#{i}].#{error.attribute}".to_sym, error.) end end end if self.class.active_json_model_array_serialization_tuple.validate_proc # It's a proc (likely lambda) if self.class.active_json_model_array_serialization_tuple.validate_proc.arity == 4 # Handle the validator_for_item_type validators that need to take the self as a param # for recursive validators self.class.active_json_model_array_serialization_tuple.validate_proc.call(val, i, errors, self) else self.class.active_json_model_array_serialization_tuple.validate_proc.call(val, i, errors) end elsif self.class.active_json_model_array_serialization_tuple.validate_method # It's implemented as method on this object send(self.class.active_json_model_array_serialization_tuple.validate_method, val, i) end end end |