Sha256: b481bb395659df64ff16b9ac38fd3841bf6bac5eba38fe3c356ac7f1a81201e9

Contents?: true

Size: 635 Bytes

Versions: 8

Compression:

Stored size: 635 Bytes

Contents

module ActiveData
  module Model
    module Validations
      class AssociatedValidator < ActiveModel::EachValidator
        def validate_each(record, attribute, value)
          invalid_records = Array.wrap(value).reject do |r|
            r.respond_to?(:valid?) && r.valid?(record.validation_context)
          end
          record.errors.add(attribute, :invalid, options.merge(value: value)) if invalid_records.present?
        end
      end

      module HelperMethods
        def validates_associated(*attr_names)
          validates_with AssociatedValidator, _merge_attributes(attr_names)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active_data-1.1.7 lib/active_data/model/validations/associated.rb
active_data-1.1.6 lib/active_data/model/validations/associated.rb
active_data-1.1.5 lib/active_data/model/validations/associated.rb
active_data-1.1.4 lib/active_data/model/validations/associated.rb
active_data-1.1.3 lib/active_data/model/validations/associated.rb
active_data-1.1.2 lib/active_data/model/validations/associated.rb
active_data-1.1.1 lib/active_data/model/validations/associated.rb
active_data-1.1.0 lib/active_data/model/validations/associated.rb