tempfile 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -0
  3. data/lib/tempfile.rb +34 -8
  4. data/tempfile.gemspec +5 -4
  5. metadata +9 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ccc754d48cea474a69828abfd078e10caca47c832b2f9ff8d21f9a64f1e0f22
4
- data.tar.gz: 2ee1ed2819d49208a4501c1a5e4ecc25707e2d53e331696b9f7d0fb460d30538
3
+ metadata.gz: 81526e805ff1c01179bcb8d4a5268f2f729eca5de5b6df55ce9f8905ed15b62a
4
+ data.tar.gz: 6dbfceb5fa00e8054da32f3af7263cd5518a1b644d6a2db4eaf2cfc3660c8b91
5
5
  SHA512:
6
- metadata.gz: e7b403c598ec72689933ffab89f635e28a61029cc421852b842a064aa92d2ef863cc67b83535bec4b70ef483add54b02460d5b540a1ab8427e6d86196669e4df
7
- data.tar.gz: 12536bd046614d957e368353c27cc4961f86ca6b404963aa1ebd094377055404c1c31dc09fff99124bc7ae151888118dfecdd9eb205e11fe57696cf11cde8598
6
+ metadata.gz: 6ffabe44885939cbda830802b5520971912636cba72d1e0ce67755fb476b9d4c0977bf95962d515d66d4a2bc748c5a573decc03565723632d548976f0d66fb65
7
+ data.tar.gz: a2671b0f516fb7b0028fde4a1a07e9c83f7f4943f9586f47d80d79cd6a122997ff4582612fe149def64882021524c97330ca70f718d3f001219be8ffa503278d
data/Rakefile CHANGED
@@ -7,4 +7,11 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/test_*.rb"]
8
8
  end
9
9
 
10
+ task :sync_tool do
11
+ require 'fileutils'
12
+ FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
13
+ FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
14
+ FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
15
+ end
16
+
10
17
  task :default => :test
@@ -53,6 +53,14 @@ require 'tmpdir'
53
53
  # file.unlink # deletes the temp file
54
54
  # end
55
55
  #
56
+ # Tempfile.create { ... } exists for this purpose and is more convenient to use.
57
+ # Note that Tempfile.create returns a File instance instead of a Tempfile, which
58
+ # also avoids the overhead and complications of delegation.
59
+ #
60
+ # Tempfile.open('foo') do |file|
61
+ # # ...do something with file...
62
+ # end
63
+ #
56
64
  # === Unlink after creation
57
65
  #
58
66
  # On POSIX systems, it's possible to unlink a file right after creating it,
@@ -82,6 +90,10 @@ class Tempfile < DelegateClass(File)
82
90
  # Creates a temporary file with permissions 0600 (= only readable and
83
91
  # writable by the owner) and opens it with mode "w+".
84
92
  #
93
+ # It is recommended to use Tempfile.create { ... } instead when possible,
94
+ # because that method avoids the cost of delegation and does not rely on a
95
+ # finalizer to close and unlink the file, which is unreliable.
96
+ #
85
97
  # The +basename+ parameter is used to determine the name of the
86
98
  # temporary file. You can either pass a String or an Array with
87
99
  # 2 String elements. In the former form, the temporary file's base
@@ -263,11 +275,25 @@ class Tempfile < DelegateClass(File)
263
275
 
264
276
  # Creates a new Tempfile.
265
277
  #
278
+ # This method is not recommended and exists mostly for backward compatibility.
279
+ # Please use Tempfile.create instead, which avoids the cost of delegation,
280
+ # does not rely on a finalizer, and also unlinks the file when given a block.
281
+ #
282
+ # Tempfile.open is still appropriate if you need the Tempfile to be unlinked
283
+ # by a finalizer and you cannot explicitly know where in the program the
284
+ # Tempfile can be unlinked safely.
285
+ #
266
286
  # If no block is given, this is a synonym for Tempfile.new.
267
287
  #
268
288
  # If a block is given, then a Tempfile object will be constructed,
269
- # and the block is run with said object as argument. The Tempfile
289
+ # and the block is run with the Tempfile object as argument. The Tempfile
270
290
  # object will be automatically closed after the block terminates.
291
+ # However, the file will *not* be unlinked and needs to be manually unlinked
292
+ # with Tempfile#close! or Tempfile#unlink. The finalizer will try to unlink
293
+ # but should not be relied upon as it can keep the file on the disk much
294
+ # longer than intended. For instance, on CRuby, finalizers can be delayed
295
+ # due to conservative stack scanning and references left in unused memory.
296
+ #
271
297
  # The call returns the value of the block.
272
298
  #
273
299
  # In any case, all arguments (<code>*args</code>) will be passed to Tempfile.new.
@@ -299,22 +325,22 @@ class Tempfile < DelegateClass(File)
299
325
  end
300
326
  end
301
327
 
302
- # Creates a temporary file as usual File object (not Tempfile).
303
- # It doesn't use finalizer and delegation.
328
+ # Creates a temporary file as a usual File object (not a Tempfile).
329
+ # It does not use finalizer and delegation, which makes it more efficient and reliable.
304
330
  #
305
331
  # If no block is given, this is similar to Tempfile.new except
306
- # creating File instead of Tempfile.
307
- # The created file is not removed automatically.
308
- # You should use File.unlink to remove it.
332
+ # creating File instead of Tempfile. In that case, the created file is
333
+ # not removed automatically. You should use File.unlink to remove it.
309
334
  #
310
335
  # If a block is given, then a File object will be constructed,
311
336
  # and the block is invoked with the object as the argument.
312
337
  # The File object will be automatically closed and
313
- # the temporary file is removed after the block terminates.
338
+ # the temporary file is removed after the block terminates,
339
+ # releasing all resources that the block created.
314
340
  # The call returns the value of the block.
315
341
  #
316
342
  # In any case, all arguments (+basename+, +tmpdir+, +mode+, and
317
- # <code>**options</code>) will be treated as Tempfile.new.
343
+ # <code>**options</code>) will be treated the same as for Tempfile.new.
318
344
  #
319
345
  # Tempfile.create('foo', '/home/temp') do |f|
320
346
  # # ... do something with f ...
@@ -1,12 +1,13 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "tempfile"
3
- spec.version = "0.1.0"
4
- spec.authors = ["Yukihiro Matsumoto"]
5
- spec.email = ["matz@ruby-lang.org"]
3
+ spec.version = "0.1.1"
4
+ spec.authors = ["Yukihiro Matsumoto"]
5
+ spec.email = ["matz@ruby-lang.org"]
6
6
 
7
7
  spec.summary = %q{A utility class for managing temporary files.}
8
8
  spec.description = %q{A utility class for managing temporary files.}
9
9
  spec.homepage = "https://github.com/ruby/tempfile"
10
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
10
11
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
11
12
 
12
13
  spec.metadata["homepage_uri"] = spec.homepage
@@ -15,7 +16,7 @@ Gem::Specification.new do |spec|
15
16
  # Specify which files should be added to the gem when it is released.
16
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
18
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ `git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
20
  end
20
21
  spec.bindir = "exe"
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tempfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-01 00:00:00.000000000 Z
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A utility class for managing temporary files.
14
14
  email:
@@ -28,11 +28,13 @@ files:
28
28
  - lib/tempfile.rb
29
29
  - tempfile.gemspec
30
30
  homepage: https://github.com/ruby/tempfile
31
- licenses: []
31
+ licenses:
32
+ - Ruby
33
+ - BSD-2-Clause
32
34
  metadata:
33
35
  homepage_uri: https://github.com/ruby/tempfile
34
36
  source_code_uri: https://github.com/ruby/tempfile
35
- post_install_message:
37
+ post_install_message:
36
38
  rdoc_options: []
37
39
  require_paths:
38
40
  - lib
@@ -47,8 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
49
  - !ruby/object:Gem::Version
48
50
  version: '0'
49
51
  requirements: []
50
- rubygems_version: 3.2.0.pre1
51
- signing_key:
52
+ rubygems_version: 3.2.2
53
+ signing_key:
52
54
  specification_version: 4
53
55
  summary: A utility class for managing temporary files.
54
56
  test_files: []