Sha256: 6a830f26145052009ca9766875bafc18d3148d4f8c7cd7cebb2313c90fca6fe0
Contents?: true
Size: 1.03 KB
Versions: 3
Compression:
Stored size: 1.03 KB
Contents
module Attachs module Extensions module ActiveRecord module Validations extend ActiveSupport::Concern class AttachmentContentTypeValidator < AttachmentValidator def validate_attachment(record, attachment) unless attachment.blank? if options.has_key?(:with) if options[:with] !~ attachment.content_type attachment.errors.add :value, :not_allowed end elsif options.has_key?(:in) || options.has_key?(:within) list = (options[:in] || options[:within]) if list.exclude?(attachment.content_type) attachment.errors.add :value, :can_only_be, list: list.to_sentence end end end end end module ClassMethods def validates_attachment_content_type_of(*attributes) validates_with AttachmentContentTypeValidator, _merge_attributes(attributes) end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems