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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b8084e7784024b9c63dd21c662696342c2c3d7cc39047bccdefb5ea8a487fa9
4
- data.tar.gz: '09b7e833cf5393f68814b1a0b616e5e1b27ed88eeb59baf92b24eb25c09d3128'
3
+ metadata.gz: 59da517113ac08b4c37ae3dcbaa3df4eb990f5f580a7b039830b7dcd3dd23e1b
4
+ data.tar.gz: e6e6efb2cdf60669ad754f9d88448c5ef131e101aed975a05b190b7366c41c11
5
5
  SHA512:
6
- metadata.gz: 6af21a139b69773da702d514009c82eebf573cfb9cd2ccea99316098e76208f6ba838ac9cdacaa8a508f0ceb75311ec2b437a5576228ed74ed3041cfbadd14d3
7
- data.tar.gz: a4a7f9e10aa3a8b4879d6a3cdd6f39f8a071e4c7e94b5249167b6ee32d481b69c8b633229c562cd33aa33758b5c50a7a13e9efb08cfd3018fff06ebfc6f9f88d
6
+ metadata.gz: 2e91fa0f70049a3bd1c666c8378423598b1a42dd8d5592d6a048c78d3de2522bd424b76e4701164f6e04e2a377b074a7eefa3e21bb0e9313baf8eed1aca5e532
7
+ data.tar.gz: e28714f6b8d3a724d688289e6eabca3362e56ba0bd4104e9ea973bebfd97ee1fdfd509b3048243fdb241d54d8c18541b7b79a162aff4bc85f3d2b9fffa3b365c
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -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@v2
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
- # Creates a temporary file with permissions 0600 (= only readable and
91
- # writable by the owner) and opens it with mode "w+".
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
- # 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.
113
+ # Example:
96
114
  #
97
- # The +basename+ parameter is used to determine the name of the
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
+ # 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
- # file = Tempfile.new('hello')
105
- # file.path # => something like: "/tmp/hello2843-8392-92849382--0"
123
+ # Argument +basename+, if given, may be one of:
106
124
  #
107
- # # Use the Array form to enforce an extension in the filename:
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
- # The temporary file will be placed in the directory as specified
112
- # by the +tmpdir+ parameter. By default, this is +Dir.tmpdir+.
127
+ # Tempfile.new('foo') # => #<Tempfile:/tmp/foo20220505-17839-1whk2f>
113
128
  #
114
- # file = Tempfile.new('hello', '/home/aisaka')
115
- # file.path # => something like: "/home/aisaka/hello2843-8392-92849382--0"
129
+ # - An array of two strings <tt>[prefix, suffix]</tt>:
130
+ # the generated filename begins with +prefix+ and ends with +suffix+:
116
131
  #
117
- # You can also pass an options hash. Under the hood, Tempfile creates
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
- # Tempfile.new('hello', '/home/aisaka', encoding: 'ascii-8bit')
134
+ # With arguments +basename+ and +tmpdir+, the file is created in directory +tmpdir+:
123
135
  #
124
- # # You can also omit the 'tmpdir' parameter:
125
- # Tempfile.new('hello', encoding: 'ascii-8bit')
136
+ # Tempfile.new('foo', '.') # => #<Tempfile:./foo20220505-17839-xfstr8>
126
137
  #
127
- # Note: +mode+ keyword argument, as accepted by Tempfile, can only be
128
- # numeric, combination of the modes defined in File::Constants.
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
- # === Exceptions
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 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.
342
+ # Creates a file in the underlying file system;
343
+ # returns a new \File object based on that file.
330
344
  #
331
- # If no block is given, this is similar to Tempfile.new except
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
- # If a block is given, then a File object will be constructed,
336
- # and the block is invoked with the object as the argument.
337
- # The File object will be automatically closed and
338
- # the temporary file is removed after the block terminates,
339
- # releasing all resources that the block created.
340
- # The call returns the value of the block.
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
- # In any case, all arguments (+basename+, +tmpdir+, +mode+, and
343
- # <code>**options</code>) will be treated the same as for Tempfile.new.
354
+ # With no block, the file is not removed automatically,
355
+ # and so should be explicitly removed.
344
356
  #
345
- # Tempfile.create('foo', '/home/temp') do |f|
346
- # # ... do something with f ...
347
- # end
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.2"
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-19 00:00:00.000000000 Z
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.3.0.dev
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.