module FilePool require 'digest/md5' class Pool def initialize(pool_path) @pool_path = pool_path Dir.mkdir @pool_path unless Dir.exist? @pool_path end def puts(row_data) md5 = Digest::MD5.hexdigest(row_data) file_path = File.join(@pool_path, md5) File.open(file_path, 'w+').write(row_data) unless File.exist? file_path return md5 end def delete(file_id) file_path = File.join(@pool_path, file_id) File.unlink file_path if File.exist? file_path end def exist?(file_id) File.exist? File.join(@pool_path, file_id) end end end