Sha256: 32df865e91402d176978fd47e591e4ed8f44be77d94188bf4511de793408b383
Contents?: true
Size: 588 Bytes
Versions: 1
Compression:
Stored size: 588 Bytes
Contents
module ActiveData module Model module Validations class AssociatedValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if Array.wrap(value).reject { |r| r.respond_to?(:valid?) && r.valid?(record.validation_context) }.any? record.errors.add(attribute, :invalid, options.merge(value: value)) end end end module HelperMethods def validates_associated(*attr_names) validates_with AssociatedValidator, _merge_attributes(attr_names) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_data-1.0.0 | lib/active_data/model/validations/associated.rb |