Sha256: bdcf6604d4e8f1e28ba117cafe391cae2113aee37bab7e25750740e4f00f7004

Contents?: true

Size: 619 Bytes

Versions: 6

Compression:

Stored size: 619 Bytes

Contents

module ActiveRecord
  module Validations
    class AssociatedBubblingValidator < ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        (value.is_a?(Array) ? value : [value]).each do |v|
          unless v.valid?
            v.errors.full_messages.each do |msg|
              record.errors.add(attribute, msg, options.merge(:value => value))
            end
          end
        end
      end
    end

    module ClassMethods
      def validates_associated_bubbling(*attr_names)
        validates_with AssociatedBubblingValidator, _merge_attributes(attr_names)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
piggybak_variants-0.0.17 lib/associated_bubbling_validator.rb
piggybak_variants-0.0.15 lib/associated_bubbling_validator.rb
piggybak_variants-0.0.14 lib/associated_bubbling_validator.rb
piggybak_variants-0.0.13 lib/associated_bubbling_validator.rb
piggybak_variants-0.0.12 lib/associated_bubbling_validator.rb
piggybak_variants-0.0.11 lib/associated_bubbling_validator.rb