Sha256: a01c4a8e070f8f73b1a8e99cdb402487a38d12c09041e4a5992aa938596d37be
Contents?: true
Size: 1.02 KB
Versions: 5
Compression:
Stored size: 1.02 KB
Contents
require 'active_model/validations/presence' module Paperclip module Validators class MediaTypeSpoofDetectionValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) adapter = Paperclip.io_adapters.for(value) if Paperclip::MediaTypeSpoofDetector.using(adapter, value.original_filename).spoofed? record.errors.add(attribute, :spoofed_media_type) end end end module HelperMethods # Places ActiveModel validations on the presence of a file. # Options: # * +if+: A lambda or name of an instance method. Validation will only # be run if this lambda or method returns true. # * +unless+: Same as +if+ but validates if lambda or method returns false. def validates_media_type_spoof_detection(*attr_names) options = _merge_attributes(attr_names) validates_with MediaTypeSpoofDetectionValidator, options.dup validate_before_processing MediaTypeSpoofDetectionValidator, options.dup end end end end
Version data entries
5 entries across 5 versions & 1 rubygems