mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
backport Tempfile.create so psych tests will run outside ruby trunk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
621c6dda36
commit
c94b0e8568
1 changed files with 29 additions and 0 deletions
|
@ -83,3 +83,32 @@ module Psych
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# backport so that tests will run on 1.9 and 2.0.0
|
||||
unless Tempfile.respond_to? :create
|
||||
def Tempfile.create(basename, *rest)
|
||||
tmpfile = nil
|
||||
Dir::Tmpname.create(basename, *rest) do |tmpname, n, opts|
|
||||
mode = File::RDWR|File::CREAT|File::EXCL
|
||||
perm = 0600
|
||||
if opts
|
||||
mode |= opts.delete(:mode) || 0
|
||||
opts[:perm] = perm
|
||||
perm = nil
|
||||
else
|
||||
opts = perm
|
||||
end
|
||||
tmpfile = File.open(tmpname, mode, opts)
|
||||
end
|
||||
if block_given?
|
||||
begin
|
||||
yield tmpfile
|
||||
ensure
|
||||
tmpfile.close if !tmpfile.closed?
|
||||
File.unlink tmpfile
|
||||
end
|
||||
else
|
||||
tmpfile
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue