1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test/helpers/tmp_path.rb
2020-07-12 20:00:29 +03:00

37 lines
573 B
Ruby

module TmpPath
def run(*args)
begin
result = super(*args)
rescue Interrupt
clean_tmp_paths
raise
end
clean_tmp_paths
result
end
private
def tmp_path(extension=nil)
sock_file = Tempfile.new(['', extension])
path = sock_file.path
sock_file.close!
tmp_paths << path
path
end
def tmp_paths
@tmp_paths ||= []
end
def clean_tmp_paths
tmp_paths.each { |path| delete_tmp_path(path) }
@tmp_paths = []
end
def delete_tmp_path(path)
File.unlink(path)
rescue Errno::ENOENT
end
end