Sha256: 6a4b932231a9b745d72be3ff95b40d95c87f7085f4cd3bf5981cf884c542e0dd
Contents?: true
Size: 1.04 KB
Versions: 2
Compression:
Stored size: 1.04 KB
Contents
module Mutations class FileFilter < AdditionalFilter @default_options = { :nils => false, # true allows an explicit nil to be valid. Overrides any other options :upload => false, # if true, also checks the file is has original_filename and content_type methods. :size => nil # An integer value like 1_000_000 limits the size of the file to 1M bytes } def filter(data) # Handle nil case if data.nil? return [nil, nil] if options[:nils] return [nil, :nils] end # Now check if it's empty: return [data, :empty] if data == "" # Ensure the data responds to each of the methods methods = [:read, :size] methods.concat([:original_filename, :content_type]) if options[:upload] methods.each do |method| return [data, :file] unless data.respond_to?(method) end if options[:size].is_a?(Fixnum) return [data, :size] if data.size > options[:size] end # We win, it's valid! [data, nil] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mutations-0.8.0 | lib/mutations/file_filter.rb |
mutations-0.7.2 | lib/mutations/file_filter.rb |