Sha256: c3c3dcedeb9c33dc18df5905653f065fe53c1e97a43d658a86ea6695af203042

Contents?: true

Size: 993 Bytes

Versions: 3

Compression:

Stored size: 993 Bytes

Contents

module Attachs
  module Extensions
    module ActiveRecord
      module Validations
        extend ActiveSupport::Concern

        class AttachmentValidator < ActiveModel::EachValidator

          def validate_each(record, record_attribute, attachment_or_collection)
            case attachment_or_collection
            when Collection
              attachment_or_collection.each do |attachment|
                validate_attachment record, attachment
                if attachment.errors.any?
                  record.errors.add record_attribute
                end
              end
            when Attachment
              validate_attachment record, attachment_or_collection
              if attachment_or_collection.errors.any?
                attachment_or_collection.errors.each do |attachment_attribute, message|
                  record.errors.add record_attribute, message
                end
              end
            end
          end

        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attachs-4.0.0.5 lib/attachs/extensions/active_record/validations/attachment_validator.rb
attachs-4.0.0.4 lib/attachs/extensions/active_record/validations/attachment_validator.rb
attachs-4.0.0.3 lib/attachs/extensions/active_record/validations/attachment_validator.rb