tempfile 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/test.yml +10 -4
- data/Gemfile +1 -0
- data/Rakefile +0 -7
- data/lib/tempfile.rb +100 -49
- data/tempfile.gemspec +10 -5
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 441e2cb96bc4f1d0c808dbde645e2985849607d7edd297b2e26fa427094eaa59
|
4
|
+
data.tar.gz: fcaf9af92f27ac9c91877ae3542dcada76e95e4c31196fbf01fa7a6213d47fea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 664dd5cdf708cf51e87f1ed8b375bf754c48dfecac717c119cfff8298018132762a4debc1b65d420128071ef6db28f893e589a5f0dc6a5e13738afc167c7436b
|
7
|
+
data.tar.gz: 4237b4700b4a8d365931e286e1e199a79c362f70ce9349d1c19bc43fb2a78f461b384e4ba1e49c7ca8967d0ae474865018c45481c8813d979bf63a47561cd2bf
|
data/.github/workflows/test.yml
CHANGED
@@ -3,15 +3,21 @@ name: ubuntu
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
ruby-versions:
|
7
|
+
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
|
8
|
+
with:
|
9
|
+
engine: cruby
|
10
|
+
min_version: 2.5
|
11
|
+
test:
|
12
|
+
needs: ruby-versions
|
7
13
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
14
|
strategy:
|
9
15
|
matrix:
|
10
|
-
ruby:
|
11
|
-
os: [ ubuntu-latest, macos-latest ]
|
16
|
+
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
|
17
|
+
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
12
18
|
runs-on: ${{ matrix.os }}
|
13
19
|
steps:
|
14
|
-
- uses: actions/checkout@
|
20
|
+
- uses: actions/checkout@v4
|
15
21
|
- name: Set up Ruby
|
16
22
|
uses: ruby/setup-ruby@v1
|
17
23
|
with:
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -7,11 +7,4 @@ 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/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
|
-
|
17
10
|
task :default => :test
|
data/lib/tempfile.rb
CHANGED
@@ -57,7 +57,7 @@ require 'tmpdir'
|
|
57
57
|
# Note that Tempfile.create returns a File instance instead of a Tempfile, which
|
58
58
|
# also avoids the overhead and complications of delegation.
|
59
59
|
#
|
60
|
-
# Tempfile.
|
60
|
+
# Tempfile.create('foo') do |file|
|
61
61
|
# # ...do something with file...
|
62
62
|
# end
|
63
63
|
#
|
@@ -87,50 +87,66 @@ require 'tmpdir'
|
|
87
87
|
# same Tempfile object from multiple threads then you should protect it with a
|
88
88
|
# mutex.
|
89
89
|
class Tempfile < DelegateClass(File)
|
90
|
-
|
91
|
-
|
90
|
+
|
91
|
+
VERSION = "0.2.0"
|
92
|
+
|
93
|
+
# Creates a file in the underlying file system;
|
94
|
+
# returns a new \Tempfile object based on that file.
|
95
|
+
#
|
96
|
+
# If possible, consider instead using Tempfile.create, which:
|
97
|
+
#
|
98
|
+
# - Avoids the performance cost of delegation,
|
99
|
+
# incurred when Tempfile.new calls its superclass <tt>DelegateClass(File)</tt>.
|
100
|
+
# - Does not rely on a finalizer to close and unlink the file,
|
101
|
+
# which can be unreliable.
|
102
|
+
#
|
103
|
+
# Creates and returns file whose:
|
104
|
+
#
|
105
|
+
# - Class is \Tempfile (not \File, as in Tempfile.create).
|
106
|
+
# - Directory is the system temporary directory (system-dependent).
|
107
|
+
# - Generated filename is unique in that directory.
|
108
|
+
# - Permissions are <tt>0600</tt>;
|
109
|
+
# see {File Permissions}[https://docs.ruby-lang.org/en/master/File.html#label-File+Permissions].
|
110
|
+
# - Mode is <tt>'w+'</tt> (read/write mode, positioned at the end).
|
92
111
|
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
# finalizer to close and unlink the file, which is unreliable.
|
112
|
+
# The underlying file is removed when the \Tempfile object dies
|
113
|
+
# and is reclaimed by the garbage collector.
|
96
114
|
#
|
97
|
-
#
|
98
|
-
# temporary file. You can either pass a String or an Array with
|
99
|
-
# 2 String elements. In the former form, the temporary file's base
|
100
|
-
# name will begin with the given string. In the latter form,
|
101
|
-
# the temporary file's base name will begin with the array's first
|
102
|
-
# element, and end with the second element. For example:
|
115
|
+
# Example:
|
103
116
|
#
|
104
|
-
#
|
105
|
-
#
|
117
|
+
# f = Tempfile.new # => #<Tempfile:/tmp/20220505-17839-1s0kt30>
|
118
|
+
# f.class # => Tempfile
|
119
|
+
# f.path # => "/tmp/20220505-17839-1s0kt30"
|
120
|
+
# f.stat.mode.to_s(8) # => "100600"
|
121
|
+
# File.exist?(f.path) # => true
|
122
|
+
# File.unlink(f.path) #
|
123
|
+
# File.exist?(f.path) # => false
|
106
124
|
#
|
107
|
-
#
|
108
|
-
# file = Tempfile.new(['hello', '.jpg'])
|
109
|
-
# file.path # => something like: "/tmp/hello2843-8392-92849382--0.jpg"
|
125
|
+
# Argument +basename+, if given, may be one of:
|
110
126
|
#
|
111
|
-
#
|
112
|
-
# by the +tmpdir+ parameter. By default, this is +Dir.tmpdir+.
|
127
|
+
# - A string: the generated filename begins with +basename+:
|
113
128
|
#
|
114
|
-
#
|
115
|
-
# file.path # => something like: "/home/aisaka/hello2843-8392-92849382--0"
|
129
|
+
# Tempfile.new('foo') # => #<Tempfile:/tmp/foo20220505-17839-1whk2f>
|
116
130
|
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
# +File.open+. This is mostly useful for specifying encoding
|
120
|
-
# options, e.g.:
|
131
|
+
# - An array of two strings <tt>[prefix, suffix]</tt>:
|
132
|
+
# the generated filename begins with +prefix+ and ends with +suffix+:
|
121
133
|
#
|
122
|
-
#
|
134
|
+
# Tempfile.new(%w/foo .jpg/) # => #<Tempfile:/tmp/foo20220505-17839-58xtfi.jpg>
|
123
135
|
#
|
124
|
-
#
|
125
|
-
# Tempfile.new('hello', encoding: 'ascii-8bit')
|
136
|
+
# With arguments +basename+ and +tmpdir+, the file is created in directory +tmpdir+:
|
126
137
|
#
|
127
|
-
#
|
128
|
-
# numeric, combination of the modes defined in File::Constants.
|
138
|
+
# Tempfile.new('foo', '.') # => #<Tempfile:./foo20220505-17839-xfstr8>
|
129
139
|
#
|
130
|
-
#
|
140
|
+
# Keyword arguments +mode+ and +options+ are passed directly to method
|
141
|
+
# {File.open}[https://docs.ruby-lang.org/en/master/File.html#method-c-open]:
|
142
|
+
#
|
143
|
+
# - The value given with +mode+ must be an integer,
|
144
|
+
# and may be expressed as the logical OR of constants defined in
|
145
|
+
# {File::Constants}[https://docs.ruby-lang.org/en/master/File/Constants.html].
|
146
|
+
# - For +options+, see {Open Options}[https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Open+Options].
|
147
|
+
#
|
148
|
+
# Related: Tempfile.create.
|
131
149
|
#
|
132
|
-
# If Tempfile.new cannot find a unique filename within a limited
|
133
|
-
# number of tries, then it will raise an exception.
|
134
150
|
def initialize(basename="", tmpdir=nil, mode: 0, **options)
|
135
151
|
warn "Tempfile.new doesn't call the given block.", uplevel: 1 if block_given?
|
136
152
|
|
@@ -325,26 +341,61 @@ class Tempfile < DelegateClass(File)
|
|
325
341
|
end
|
326
342
|
end
|
327
343
|
|
328
|
-
# Creates a
|
329
|
-
#
|
344
|
+
# Creates a file in the underlying file system;
|
345
|
+
# returns a new \File object based on that file.
|
330
346
|
#
|
331
|
-
#
|
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.
|
347
|
+
# With no block given and no arguments, creates and returns file whose:
|
334
348
|
#
|
335
|
-
#
|
336
|
-
#
|
337
|
-
#
|
338
|
-
#
|
339
|
-
#
|
340
|
-
#
|
349
|
+
# - Class is {File}[https://docs.ruby-lang.org/en/master/File.html] (not \Tempfile).
|
350
|
+
# - Directory is the system temporary directory (system-dependent).
|
351
|
+
# - Generated filename is unique in that directory.
|
352
|
+
# - Permissions are <tt>0600</tt>;
|
353
|
+
# see {File Permissions}[https://docs.ruby-lang.org/en/master/File.html#label-File+Permissions].
|
354
|
+
# - Mode is <tt>'w+'</tt> (read/write mode, positioned at the end).
|
341
355
|
#
|
342
|
-
#
|
343
|
-
#
|
356
|
+
# With no block, the file is not removed automatically,
|
357
|
+
# and so should be explicitly removed.
|
344
358
|
#
|
345
|
-
#
|
346
|
-
#
|
347
|
-
#
|
359
|
+
# Example:
|
360
|
+
#
|
361
|
+
# f = Tempfile.create # => #<File:/tmp/20220505-9795-17ky6f6>
|
362
|
+
# f.class # => File
|
363
|
+
# f.path # => "/tmp/20220505-9795-17ky6f6"
|
364
|
+
# f.stat.mode.to_s(8) # => "100600"
|
365
|
+
# File.exist?(f.path) # => true
|
366
|
+
# File.unlink(f.path)
|
367
|
+
# File.exist?(f.path) # => false
|
368
|
+
#
|
369
|
+
# Argument +basename+, if given, may be one of:
|
370
|
+
#
|
371
|
+
# - A string: the generated filename begins with +basename+:
|
372
|
+
#
|
373
|
+
# Tempfile.create('foo') # => #<File:/tmp/foo20220505-9795-1gok8l9>
|
374
|
+
#
|
375
|
+
# - An array of two strings <tt>[prefix, suffix]</tt>:
|
376
|
+
# the generated filename begins with +prefix+ and ends with +suffix+:
|
377
|
+
#
|
378
|
+
# Tempfile.create(%w/foo .jpg/) # => #<File:/tmp/foo20220505-17839-tnjchh.jpg>
|
379
|
+
#
|
380
|
+
# With arguments +basename+ and +tmpdir+, the file is created in directory +tmpdir+:
|
381
|
+
#
|
382
|
+
# Tempfile.create('foo', '.') # => #<File:./foo20220505-9795-1emu6g8>
|
383
|
+
#
|
384
|
+
# Keyword arguments +mode+ and +options+ are passed directly to method
|
385
|
+
# {File.open}[https://docs.ruby-lang.org/en/master/File.html#method-c-open]:
|
386
|
+
#
|
387
|
+
# - The value given with +mode+ must be an integer,
|
388
|
+
# and may be expressed as the logical OR of constants defined in
|
389
|
+
# {File::Constants}[https://docs.ruby-lang.org/en/master/File/Constants.html].
|
390
|
+
# - For +options+, see {Open Options}[https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Open+Options].
|
391
|
+
#
|
392
|
+
# With a block given, creates the file as above, passes it to the block,
|
393
|
+
# and returns the block's value;
|
394
|
+
# before the return, the file object is closed and the underlying file is removed:
|
395
|
+
#
|
396
|
+
# Tempfile.create {|file| file.path } # => "/tmp/20220505-9795-rkists"
|
397
|
+
#
|
398
|
+
# Related: Tempfile.new.
|
348
399
|
#
|
349
400
|
def Tempfile.create(basename="", tmpdir=nil, mode: 0, **options)
|
350
401
|
tmpfile = nil
|
data/tempfile.gemspec
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
name = File.basename(__FILE__, ".gemspec")
|
2
|
+
version = ["lib", Array.new(name.count("-")+1).join("/")].find do |dir|
|
3
|
+
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
|
4
|
+
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
|
5
|
+
end rescue nil
|
6
|
+
end
|
7
|
+
|
1
8
|
Gem::Specification.new do |spec|
|
2
|
-
spec.name =
|
3
|
-
spec.version =
|
9
|
+
spec.name = name
|
10
|
+
spec.version = version
|
4
11
|
spec.authors = ["Yukihiro Matsumoto"]
|
5
12
|
spec.email = ["matz@ruby-lang.org"]
|
6
13
|
|
@@ -16,9 +23,7 @@ Gem::Specification.new do |spec|
|
|
16
23
|
# Specify which files should be added to the gem when it is released.
|
17
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
25
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
-
`git ls-files -z 2
|
26
|
+
`git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
27
|
end
|
21
|
-
spec.bindir = "exe"
|
22
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
28
|
spec.require_paths = ["lib"]
|
24
29
|
end
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A utility class for managing temporary files.
|
14
14
|
email:
|
@@ -17,6 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".github/dependabot.yml"
|
20
21
|
- ".github/workflows/test.yml"
|
21
22
|
- ".gitignore"
|
22
23
|
- Gemfile
|
@@ -49,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
50
|
- !ruby/object:Gem::Version
|
50
51
|
version: '0'
|
51
52
|
requirements: []
|
52
|
-
rubygems_version: 3.
|
53
|
+
rubygems_version: 3.5.0.dev
|
53
54
|
signing_key:
|
54
55
|
specification_version: 4
|
55
56
|
summary: A utility class for managing temporary files.
|