lib/io_streams/utils.rb in iostreams-1.0.0 vs lib/io_streams/utils.rb in iostreams-1.1.0
- old
+ new
@@ -1,7 +1,10 @@
+require 'uri'
module IOStreams
module Utils
+ MAX_TEMP_FILE_NAME_ATTEMPTS = 5
+
# Lazy load dependent gem so that it remains a soft dependency.
def self.load_soft_dependency(gem_name, stream_type, require_name = gem_name)
require require_name
rescue LoadError => e
raise(LoadError, "Please install the gem '#{gem_name}' to support #{stream_type}. #{e.message}")
@@ -21,10 +24,10 @@
# Yields the path to a temporary file_name.
#
# File is deleted upon completion if present.
def self.temp_file_name(basename, extension = '')
result = nil
- ::Dir::Tmpname.create([basename, extension]) do |tmpname|
+ ::Dir::Tmpname.create([basename, extension], IOStreams.temp_dir, max_try: MAX_TEMP_FILE_NAME_ATTEMPTS) do |tmpname|
begin
result = yield(tmpname)
ensure
::File.unlink(tmpname) if ::File.exist?(tmpname)
end