lib/shoes/swt/common/image_handling.rb in shoes-swt-4.0.0.pre12 vs lib/shoes/swt/common/image_handling.rb in shoes-swt-4.0.0.rc1
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
class Shoes
module Swt
module Common
module ImageHandling
# Why copy the file to a temporary location just to pass a different name
@@ -11,25 +12,30 @@
# in Ruby-land before handing it over.
def load_file_image_data(name)
tmpname = File.join(Dir.tmpdir, "__shoes4_#{Time.now.to_i}_#{File.basename(name)}")
FileUtils.cp(name, tmpname)
- @cleanup_files ||= []
- @cleanup_files << tmpname
+ cleanup_files << tmpname
tmpname
end
def cleanup_temporary_files
- return unless @cleanup_files
+ return unless cleanup_files.any?
- @cleanup_files.each do |file|
+ cleanup_files.each do |file|
begin
FileUtils.rm(file)
rescue => e
Shoes.logger.debug("Error during image temp file cleanup.\n#{e.class}: #{e.message}")
end
end
- @cleanup_files.clear
+ cleanup_files.clear
+ end
+
+ private
+
+ def cleanup_files
+ @cleanup_files ||= []
end
end
end
end
end