module Selenium::WebDriver::FileReaper

def <<(file)

def <<(file)
  tmp_files << file
end

def reap(file)

def reap(file)
  return unless reap?
  raise Error::WebDriverError, "file not added for reaping: #{file.inspect}" unless tmp_files.include?(file)
  FileUtils.rm_rf tmp_files.delete(file)
end

def reap!

def reap!
  if reap?
    tmp_files.each { |file| FileUtils.rm_rf(file) }
    true
  else
    false
  end
end

def reap?

def reap?
  @reap = defined?(@reap) ? @reap : true
end

def tmp_files

def tmp_files
  @tmp_files ||= Hash.new { |hash, pid| hash[pid] = [] }
  @tmp_files[Process.pid]
end