Sha256: 2f028667a10776a595ec5285e8ecec87586d19bedaf964fd74cd878a6ecbaf9d
Contents?: true
Size: 549 Bytes
Versions: 2
Compression:
Stored size: 549 Bytes
Contents
module ActiveData module Validations class AssociatedValidator < ActiveModel::EachValidator #:nodoc: 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 ClassMethods def validates_associated(*attr_names) validates_with AssociatedValidator, _merge_attributes(attr_names) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_data-0.3.0 | lib/active_data/validations/associated.rb |
active_data-0.2.0 | lib/active_data/validations/associated.rb |