Sha256: 03fdf090d0a5b61ac1cec9c1665ec08a44871ed410daba668562c24e217fcf7a

Contents?: true

Size: 658 Bytes

Versions: 3

Compression:

Stored size: 658 Bytes

Contents

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

        class AttachmentPresenceValidator < AttachmentValidator

          def validate_one(record, attribute, attachment)
            unless attachment.blank?
              record.errors.add attribute, :invalid
              attachment.errors.add :base, :blank
            end
          end

        end
        module ClassMethods

          def validates_attachment_presence_of(*attr_names)
            validates_with AttachmentPresenceValidator, _merge_attributes(attr_names)
          end

        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attachs-4.0.0.2 lib/attachs/extensions/active_record/validations/attachment_presence_validator.rb
attachs-4.0.0.1 lib/attachs/extensions/active_record/validations/attachment_presence_validator.rb
attachs-4.0.0.0 lib/attachs/extensions/active_record/validations/attachment_presence_validator.rb