Skip to content

Commit

Permalink
Bring back Ruby 2.5 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
envygeeks committed Oct 30, 2018
1 parent 372ef53 commit 99f3d30
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/pathutil/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,29 @@ def make_tmpname(prefix = "", suffix = nil, root = nil)
suffix = tmpname_suffix(suffix)

root ||= Dir::Tmpname.tmpdir
File.join(root, Dir::Tmpname.make_tmpname(
File.join(root, __make_tmpname(
prefix, suffix
))
end

# --
private
def __make_tmpname((prefix, suffix), number)
prefix &&= String.try_convert(prefix) || tmpname_agerr(:prefix, prefix)
suffix &&= String.try_convert(suffix) || tmpname_agerr(:suffix, suffix)

time = Time.now.strftime("%Y%m%d")
path = "#{prefix}#{time}-#{$$}-#{rand(0x100000000).to_s(36)}".dup
path << "-#{number}" if number
path << suffix if suffix
path
end

private
def tmpname_agerr(type, val)
raise ArgumentError, "unexpected #{type}: #{val.inspect}"
end

# --
private
def tmpname_suffix(suffix)
Expand Down

0 comments on commit 99f3d30

Please sign in to comment.