class Mutations::FileFilter

Public Instance Methods

filter(data) click to toggle source
# File lib/mutations/file_filter.rb, line 9
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?(Integer)
    return [data, :size] if data.size > options[:size]
  end

  # We win, it's valid!
  [data, nil]
end