tempfile 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/test.yml +2 -2
- data/lib/tempfile.rb +97 -48
- data/tempfile.gemspec +1 -3
- 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: 59da517113ac08b4c37ae3dcbaa3df4eb990f5f580a7b039830b7dcd3dd23e1b
|
4
|
+
data.tar.gz: e6e6efb2cdf60669ad754f9d88448c5ef131e101aed975a05b190b7366c41c11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e91fa0f70049a3bd1c666c8378423598b1a42dd8d5592d6a048c78d3de2522bd424b76e4701164f6e04e2a377b074a7eefa3e21bb0e9313baf8eed1aca5e532
|
7
|
+
data.tar.gz: e28714f6b8d3a724d688289e6eabca3362e56ba0bd4104e9ea973bebfd97ee1fdfd509b3048243fdb241d54d8c18541b7b79a162aff4bc85f3d2b9fffa3b365c
|
data/.github/workflows/test.yml
CHANGED
@@ -7,11 +7,11 @@ jobs:
|
|
7
7
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [ 2.7, 2.6, 2.5, head ]
|
10
|
+
ruby: [ 3.1, '3.0', 2.7, 2.6, 2.5, head ]
|
11
11
|
os: [ ubuntu-latest, macos-latest ]
|
12
12
|
runs-on: ${{ matrix.os }}
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
14
|
+
- uses: actions/checkout@v3
|
15
15
|
- name: Set up Ruby
|
16
16
|
uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
data/lib/tempfile.rb
CHANGED
@@ -87,50 +87,64 @@ 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
|
+
# Creates a file in the underlying file system;
|
92
|
+
# returns a new \Tempfile object based on that file.
|
93
|
+
#
|
94
|
+
# If possible, consider instead using Tempfile.create, which:
|
95
|
+
#
|
96
|
+
# - Avoids the performance cost of delegation,
|
97
|
+
# incurred when Tempfile.new calls its superclass <tt>DelegateClass(File)</tt>.
|
98
|
+
# - Does not rely on a finalizer to close and unlink the file,
|
99
|
+
# which can be unreliable.
|
100
|
+
#
|
101
|
+
# Creates and returns file whose:
|
102
|
+
#
|
103
|
+
# - Class is \Tempfile (not \File, as in Tempfile.create).
|
104
|
+
# - Directory is the system temporary directory (system-dependent).
|
105
|
+
# - Generated filename is unique in that directory.
|
106
|
+
# - Permissions are <tt>0600</tt>;
|
107
|
+
# see {File Permissions}[https://docs.ruby-lang.org/en/master/File.html#label-File+Permissions].
|
108
|
+
# - Mode is <tt>'w+'</tt> (read/write mode, positioned at the end).
|
109
|
+
#
|
110
|
+
# The underlying file is removed when the \Tempfile object dies
|
111
|
+
# and is reclaimed by the garbage collector.
|
92
112
|
#
|
93
|
-
#
|
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.
|
113
|
+
# Example:
|
96
114
|
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
115
|
+
# f = Tempfile.new # => #<Tempfile:/tmp/20220505-17839-1s0kt30>
|
116
|
+
# f.class # => Tempfile
|
117
|
+
# f.path # => "/tmp/20220505-17839-1s0kt30"
|
118
|
+
# f.stat.mode.to_s(8) # => "100600"
|
119
|
+
# File.exist?(f.path) # => true
|
120
|
+
# File.unlink(f.path) #
|
121
|
+
# File.exist?(f.path) # => false
|
103
122
|
#
|
104
|
-
#
|
105
|
-
# file.path # => something like: "/tmp/hello2843-8392-92849382--0"
|
123
|
+
# Argument +basename+, if given, may be one of:
|
106
124
|
#
|
107
|
-
#
|
108
|
-
# file = Tempfile.new(['hello', '.jpg'])
|
109
|
-
# file.path # => something like: "/tmp/hello2843-8392-92849382--0.jpg"
|
125
|
+
# - A string: the generated filename begins with +basename+:
|
110
126
|
#
|
111
|
-
#
|
112
|
-
# by the +tmpdir+ parameter. By default, this is +Dir.tmpdir+.
|
127
|
+
# Tempfile.new('foo') # => #<Tempfile:/tmp/foo20220505-17839-1whk2f>
|
113
128
|
#
|
114
|
-
#
|
115
|
-
#
|
129
|
+
# - An array of two strings <tt>[prefix, suffix]</tt>:
|
130
|
+
# the generated filename begins with +prefix+ and ends with +suffix+:
|
116
131
|
#
|
117
|
-
#
|
118
|
-
# the temporary file using +File.open+. These options will be passed to
|
119
|
-
# +File.open+. This is mostly useful for specifying encoding
|
120
|
-
# options, e.g.:
|
132
|
+
# Tempfile.new(%w/foo .jpg/) # => #<Tempfile:/tmp/foo20220505-17839-58xtfi.jpg>
|
121
133
|
#
|
122
|
-
#
|
134
|
+
# With arguments +basename+ and +tmpdir+, the file is created in directory +tmpdir+:
|
123
135
|
#
|
124
|
-
#
|
125
|
-
# Tempfile.new('hello', encoding: 'ascii-8bit')
|
136
|
+
# Tempfile.new('foo', '.') # => #<Tempfile:./foo20220505-17839-xfstr8>
|
126
137
|
#
|
127
|
-
#
|
128
|
-
#
|
138
|
+
# Keyword arguments +mode+ and +options+ are passed directly to method
|
139
|
+
# {File.open}[https://docs.ruby-lang.org/en/master/File.html#method-c-open]:
|
129
140
|
#
|
130
|
-
#
|
141
|
+
# - The value given with +mode+ must be an integer,
|
142
|
+
# and may be expressed as the logical OR of constants defined in
|
143
|
+
# {File::Constants}[https://docs.ruby-lang.org/en/master/File/Constants.html].
|
144
|
+
# - For +options+, see {Open Options}[https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Open+Options].
|
145
|
+
#
|
146
|
+
# Related: Tempfile.create.
|
131
147
|
#
|
132
|
-
# If Tempfile.new cannot find a unique filename within a limited
|
133
|
-
# number of tries, then it will raise an exception.
|
134
148
|
def initialize(basename="", tmpdir=nil, mode: 0, **options)
|
135
149
|
warn "Tempfile.new doesn't call the given block.", uplevel: 1 if block_given?
|
136
150
|
|
@@ -325,26 +339,61 @@ class Tempfile < DelegateClass(File)
|
|
325
339
|
end
|
326
340
|
end
|
327
341
|
|
328
|
-
# Creates a
|
329
|
-
#
|
342
|
+
# Creates a file in the underlying file system;
|
343
|
+
# returns a new \File object based on that file.
|
330
344
|
#
|
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.
|
345
|
+
# With no block given and no arguments, creates and returns file whose:
|
334
346
|
#
|
335
|
-
#
|
336
|
-
#
|
337
|
-
#
|
338
|
-
#
|
339
|
-
#
|
340
|
-
#
|
347
|
+
# - Class is {File}[https://docs.ruby-lang.org/en/master/File.html] (not \Tempfile).
|
348
|
+
# - Directory is the system temporary directory (system-dependent).
|
349
|
+
# - Generated filename is unique in that directory.
|
350
|
+
# - Permissions are <tt>0600</tt>;
|
351
|
+
# see {File Permissions}[https://docs.ruby-lang.org/en/master/File.html#label-File+Permissions].
|
352
|
+
# - Mode is <tt>'w+'</tt> (read/write mode, positioned at the end).
|
341
353
|
#
|
342
|
-
#
|
343
|
-
#
|
354
|
+
# With no block, the file is not removed automatically,
|
355
|
+
# and so should be explicitly removed.
|
344
356
|
#
|
345
|
-
#
|
346
|
-
#
|
347
|
-
#
|
357
|
+
# Example:
|
358
|
+
#
|
359
|
+
# f = Tempfile.create # => #<File:/tmp/20220505-9795-17ky6f6>
|
360
|
+
# f.class # => File
|
361
|
+
# f.path # => "/tmp/20220505-9795-17ky6f6"
|
362
|
+
# f.stat.mode.to_s(8) # => "100600"
|
363
|
+
# File.exist?(f.path) # => true
|
364
|
+
# File.unlink(f.path)
|
365
|
+
# File.exist?(f.path) # => false
|
366
|
+
#
|
367
|
+
# Argument +basename+, if given, may be one of:
|
368
|
+
#
|
369
|
+
# - A string: the generated filename begins with +basename+:
|
370
|
+
#
|
371
|
+
# Tempfile.create('foo') # => #<File:/tmp/foo20220505-9795-1gok8l9>
|
372
|
+
#
|
373
|
+
# - An array of two strings <tt>[prefix, suffix]</tt>:
|
374
|
+
# the generated filename begins with +prefix+ and ends with +suffix+:
|
375
|
+
#
|
376
|
+
# Tempfile.create(%w/foo .jpg/) # => #<File:/tmp/foo20220505-17839-tnjchh.jpg>
|
377
|
+
#
|
378
|
+
# With arguments +basename+ and +tmpdir+, the file is created in directory +tmpdir+:
|
379
|
+
#
|
380
|
+
# Tempfile.create('foo', '.') # => #<File:./foo20220505-9795-1emu6g8>
|
381
|
+
#
|
382
|
+
# Keyword arguments +mode+ and +options+ are passed directly to method
|
383
|
+
# {File.open}[https://docs.ruby-lang.org/en/master/File.html#method-c-open]:
|
384
|
+
#
|
385
|
+
# - The value given with +mode+ must be an integer,
|
386
|
+
# and may be expressed as the logical OR of constants defined in
|
387
|
+
# {File::Constants}[https://docs.ruby-lang.org/en/master/File/Constants.html].
|
388
|
+
# - For +options+, see {Open Options}[https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Open+Options].
|
389
|
+
#
|
390
|
+
# With a block given, creates the file as above, passes it to the block,
|
391
|
+
# and returns the block's value;
|
392
|
+
# before the return, the file object is closed and the underlying file is removed:
|
393
|
+
#
|
394
|
+
# Tempfile.create {|file| file.path } # => "/tmp/20220505-9795-rkists"
|
395
|
+
#
|
396
|
+
# Related: Tempfile.new.
|
348
397
|
#
|
349
398
|
def Tempfile.create(basename="", tmpdir=nil, mode: 0, **options)
|
350
399
|
tmpfile = nil
|
data/tempfile.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "tempfile"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.3"
|
4
4
|
spec.authors = ["Yukihiro Matsumoto"]
|
5
5
|
spec.email = ["matz@ruby-lang.org"]
|
6
6
|
|
@@ -18,7 +18,5 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
19
|
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
20
|
end
|
21
|
-
spec.bindir = "exe"
|
22
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
21
|
spec.require_paths = ["lib"]
|
24
22
|
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.1.
|
4
|
+
version: 0.1.3
|
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: 2022-12-14 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.4.0.dev
|
53
54
|
signing_key:
|
54
55
|
specification_version: 4
|
55
56
|
summary: A utility class for managing temporary files.
|