file-temp 1.4.0 → 1.5.0

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: 9d67d648a504230473821894fe46b2a1cc1a620a446f56ddf5403948d897ec11
4
- data.tar.gz: 20f597de400fbb8fc80303a15f8565407797ae55cc4fd2d8f10e5bde193a69ea
3
+ metadata.gz: ce8a520c1d613ad4044a606a3c261c6cd385cbc23c88e51b365584a36c3b24a5
4
+ data.tar.gz: 4ea26edf5dbb7b5b99defd3ebc07eba370be758dcf81b0f9cfa0aa8c2ddb186a
5
5
  SHA512:
6
- metadata.gz: a5c7833e5672b2cfa8a2809c3d47d134a9230ae9c8442de88b46b8b7c7eb9ebccf598b5e3f9e5b116fa5d1b77094cc31b63c538a65bb338153242baebd44b070
7
- data.tar.gz: a0da5760dfdb59be495b1292eac93315c8de30ccb0c8a7c98c976f1028757bfde8cb6c09a47adc26ca0ac556b0690b5d2190f50272989308a4ec1e4551b3ad34
6
+ metadata.gz: 94e3bb9b16f1d4ee0eb582dc8e4e58d4e1d5fab1fd5ac8659abc261a60027176b24f7c5b6dd344499dd1557ef7af594c8e0326fb62b841bf4bafeafb7dd3a7a0
7
+ data.tar.gz: 9cc54ec10d6a437a4fc41cb7ac0cbbc2436f8673ffde4b5a48cff844a9a369d66df60174c3856fc060b11ef3cec10883b4168528f80b341e285ee9d920cb4b52
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,11 @@
1
+ = 1.5.0 - 8-May-2020
2
+ * Switched to keyword arguments.
3
+ * Added the ability to specify a tmp directory.
4
+ * Updates to the JRuby version, removed some code that no longer worked, and
5
+ added support for specifying your own directory.
6
+ * Added a LICENSE file to the distro as part of the Apache-2.0 requirement.
7
+ * Added explicit .rdoc extensions to the README, CHANGES and MANIFEST files.
8
+
1
9
  = 1.4.0 - 12-Oct-2019
2
10
  * Changed license to Apache-2.0.
3
11
  * VERSION constant now lives in a single place, and is frozen.
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -1,4 +1,5 @@
1
1
  * CHANGES
2
+ * LICENSE
2
3
  * MANIFEST
3
4
  * README
4
5
  * Rakefile
@@ -0,0 +1,66 @@
1
+ == Description
2
+ The file-temp library is an alternate way to handle tempfile generation.
3
+
4
+ == Requirements
5
+ * ffi 1.0.0 or later
6
+
7
+ == Installation
8
+ gem install file-temp
9
+
10
+ == Synopsis
11
+ require 'file/temp'
12
+
13
+ fh = File::Temp.new
14
+ fh.puts "hello"
15
+ fh.close # => Tempfile automatically deleted
16
+
17
+ fh = File::Temp.new(delete: false)
18
+ fh.puts "world"
19
+ fh.close # => Tempfile still on your filesystem
20
+
21
+ == Motivation
22
+ Unlike the tempfile library that ships with Ruby's standard library, this
23
+ library uses your system's native +tmpfile+ or +mkstemp+ functions.
24
+
25
+ This library is also more secure because it restricts file permission via
26
+ +umask+ for files created with +mkstemp+.
27
+
28
+ Finally, this library subclasses the File class. This means you get almost
29
+ exactly the same interface as the File class. The only difference is the
30
+ constructor.
31
+
32
+ Note that my original motivation was a problem with race conditions in
33
+ the tempfile library, but that was a very long time ago, and my assumption
34
+ at this point is that it's no longer true. But, I still prefer this version
35
+ to the one in the Ruby standard library.
36
+
37
+ == JRuby
38
+ The implementation for JRuby uses the Java API, not the C API. The
39
+ temporary file name generated by Java is different than the C version,
40
+ since it uses a GUID instead of the 'XXXXXX' template, but the
41
+ interface is otherwise identical.
42
+
43
+ == MS Windows
44
+ You may need to use the mingw build in order to use this library.
45
+
46
+ Also, there was a bug with the +GetTempFileName+ function on certain versions
47
+ of MS Windows that may cause a failure. However, if you'r patched up you
48
+ should not see it.
49
+
50
+ == License
51
+ Apache-2.0
52
+
53
+ == Copyright
54
+ (C) 2007-2020 Daniel J. Berger
55
+ All Rights Reserved
56
+
57
+ == Warranty
58
+ This library is provided "as is" and without any express or
59
+ implied warranties, including, without limitation, the implied
60
+ warranties of merchantability and fitness for a particular purpose.
61
+
62
+ == Author
63
+ Daniel J. Berger
64
+
65
+ == See also
66
+ tmpfile(), mkstemp(), tmpnam()
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'file-temp'
5
- spec.version = '1.4.0'
5
+ spec.version = '1.5.0'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Apache-2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.files = Dir['**/*'].delete_if{ |item| item.include?('git') }
13
13
  spec.cert_chain = Dir['certs/*']
14
14
 
15
- spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
15
+ spec.extra_rdoc_files = ['CHANGES.rdoc', 'README.rdoc', 'MANIFEST.rdoc']
16
16
 
17
17
  spec.add_dependency('ffi', '>= 1.0.0')
18
18
  spec.add_development_dependency('test-unit')
@@ -8,8 +8,8 @@ class File::Temp < File
8
8
  # The name of the temporary file.
9
9
  attr_reader :path
10
10
 
11
- # Creates a new, anonymous, temporary file in your File::Temp::TMPDIR
12
- # directory.
11
+ # Creates a new, anonymous, temporary file in your system's temporary
12
+ # directory, or whichever directory you specify.
13
13
  #
14
14
  # If the +delete+ option is set to true (the default) then the temporary file
15
15
  # will be deleted automatically as soon as all references to it are closed.
@@ -27,11 +27,11 @@ class File::Temp < File
27
27
  #
28
28
  # Example:
29
29
  #
30
- # fh = File::Temp.new(true, 'rb_file_temp_XXXXXX') => file
30
+ # fh = File::Temp.new(delete: true, template: 'rb_file_temp_XXXXXX')
31
31
  # fh.puts 'hello world'
32
32
  # fh.close
33
33
  #
34
- def initialize(delete = true, template = 'rb_file_temp_XXXXXX')
34
+ def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR)
35
35
  raise TypeError unless template.is_a?(String)
36
36
 
37
37
  # Since Java uses a GUID extension to generate a unique file name
@@ -41,7 +41,7 @@ class File::Temp < File
41
41
  # For consistency between implementations, convert errors here
42
42
  # to Errno::EINVAL.
43
43
  begin
44
- @file = java.io.File.createTempFile(template, nil)
44
+ @file = java.io.File.createTempFile(template, nil, java.io.File.new(directory))
45
45
  rescue NativeException => err
46
46
  raise SystemCallError.new(22), template # 22 is EINVAL
47
47
  end
@@ -54,14 +54,13 @@ class File::Temp < File
54
54
  @path = path unless delete
55
55
  end
56
56
 
57
- # Generates a unique file name.
57
+ # Generates a unique file name based on your tmpdir, or whichever
58
+ # directory you specify.
58
59
  #
59
- def self.temp_name
60
- file = java.io.File.createTempFile('rb_file_temp_', nil)
60
+ def self.temp_name(directory = TMPDIR)
61
+ file = java.io.File.createTempFile('rb_file_temp_', nil, java.io.File.new(directory))
61
62
  file.deleteOnExit
62
- name = file.getName
63
- file.finalize
64
- name
63
+ directory + file.getName
65
64
  end
66
65
 
67
66
  # Identical to the File#close method except that we also finalize
@@ -1,6 +1,6 @@
1
1
  class File::Temp < File
2
2
  # The version of the file-temp library
3
- VERSION = '1.4.0'.freeze
3
+ VERSION = '1.5.0'.freeze
4
4
  end
5
5
 
6
6
  if RUBY_PLATFORM == 'java'
@@ -23,19 +23,19 @@ class File::Temp < File
23
23
 
24
24
  # :startdoc:
25
25
 
26
- # The temporary directory used on MS Windows or Unix.
26
+ # The temporary directory used on MS Windows or Unix by default.
27
27
  TMPDIR = ENV['TEMP'] || ENV['TMP'] || ENV['TMPDIR'] || Dir.tmpdir
28
28
 
29
29
  # The name of the temporary file. Set to nil if the +delete+ option to the
30
30
  # constructor is true.
31
31
  attr_reader :path
32
32
 
33
- # Creates a new, anonymous, temporary file in your File::Temp::TMPDIR
34
- # directory
33
+ # Creates a new, anonymous, temporary file in your tmpdir, or whichever
34
+ # directory you specifiy.
35
35
  #
36
36
  # If the +delete+ option is set to true (the default) then the temporary file
37
37
  # will be deleted automatically as soon as all references to it are closed.
38
- # Otherwise, the file will live on in your File::Temp::TMPDIR path.
38
+ # Otherwise, the file will live on in your tmpdir path.
39
39
  #
40
40
  # If the +delete+ option is set to false, then the file is not deleted. In
41
41
  # addition, you can supply a string +template+ that the system replaces with
@@ -47,29 +47,28 @@ class File::Temp < File
47
47
  #
48
48
  # Example:
49
49
  #
50
- # fh = File::Temp.new(true, 'rb_file_temp_XXXXXX') => file
50
+ # fh = File::Temp.new(delete: true, template: 'rb_file_temp_XXXXXX') => file
51
51
  # fh.puts 'hello world'
52
52
  # fh.close
53
53
  #
54
- def initialize(delete = true, template = 'rb_file_temp_XXXXXX')
54
+ def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR)
55
55
  @fptr = nil
56
56
 
57
57
  if delete
58
58
  @fptr = tmpfile()
59
+ raise SystemCallError.new('tmpfile', FFI.errno) if @fptr.null?
59
60
  fd = _fileno(@fptr)
60
61
  else
61
62
  begin
62
63
  omask = File.umask(077)
63
-
64
64
  ptr = FFI::MemoryPointer.from_string(template)
65
-
66
65
  str = mktemp(ptr)
67
66
 
68
67
  if str.nil? || str.empty?
69
68
  raise SystemCallError.new('mktemp', FFI.errno)
70
69
  end
71
70
 
72
- @path = File.join(TMPDIR, ptr.read_string)
71
+ @path = File.join(directory, ptr.read_string)
73
72
  ensure
74
73
  File.umask(omask)
75
74
  end
@@ -82,13 +81,17 @@ class File::Temp < File
82
81
  end
83
82
  end
84
83
 
85
- # The close method was overridden to ensure the internal file pointer we
86
- # created in the constructor is closed. It is otherwise identical to the
87
- # File#close method.
84
+ # The close method was overridden to ensure the internal file pointer that we
85
+ # potentially created in the constructor is closed. It is otherwise identical
86
+ # to the File#close method.
87
+ #--
88
+ # This is probably unnecessary since Ruby will close the fd, and in reality
89
+ # the fclose function probably fails with an Errno::EBADF. Consequently
90
+ # I will let it silently fail as a no-op.
88
91
  #
89
92
  def close
90
93
  super
91
- fclose(@fptr) if @fptr
94
+ fclose(@fptr) if @fptr && !@fptr.null?
92
95
  end
93
96
 
94
97
  # Generates a unique file name.
@@ -53,7 +53,7 @@ class File::Temp < File
53
53
 
54
54
  # :startdoc:
55
55
 
56
- # The temporary directory used on MS Windows or Unix.
56
+ # The temporary directory used on MS Windows or Unix by default.
57
57
  TMPDIR = ENV['TEMP'] || ENV['TMP'] || ENV['USERPROFILE'] || Dir.tmpdir
58
58
 
59
59
  # The name of the temporary file. Set to nil if the +delete+ option to the
@@ -61,7 +61,7 @@ class File::Temp < File
61
61
  attr_reader :path
62
62
 
63
63
  # Creates a new, anonymous, temporary file in your File::Temp::TMPDIR
64
- # directory
64
+ # directory, or whichever directory you specify.
65
65
  #
66
66
  # If the +delete+ option is set to true (the default) then the temporary file
67
67
  # will be deleted automatically as soon as all references to it are closed.
@@ -77,11 +77,11 @@ class File::Temp < File
77
77
  #
78
78
  # Example:
79
79
  #
80
- # fh = File::Temp.new(true, 'rb_file_temp_XXXXXX') => file
80
+ # fh = File::Temp.new(delete: true, template: 'rb_file_temp_XXXXXX')
81
81
  # fh.puts 'hello world'
82
82
  # fh.close
83
83
  #
84
- def initialize(delete = true, template = 'rb_file_temp_XXXXXX')
84
+ def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR)
85
85
  @fptr = nil
86
86
 
87
87
  if delete
@@ -90,14 +90,12 @@ class File::Temp < File
90
90
  else
91
91
  begin
92
92
  omask = File.umask(077)
93
-
94
93
  ptr = FFI::MemoryPointer.from_string(template)
95
-
96
94
  errno = mktemp_s(ptr, ptr.size)
97
95
 
98
96
  raise SystemCallError.new('mktemp_s', errno) if errno != 0
99
97
 
100
- @path = File.join(TMPDIR, ptr.read_string)
98
+ @path = File.join(directory, ptr.read_string)
101
99
  @path.tr!(File::SEPARATOR, File::ALT_SEPARATOR)
102
100
  ensure
103
101
  File.umask(omask)
@@ -120,20 +118,21 @@ class File::Temp < File
120
118
  fclose(@fptr) if @fptr
121
119
  end
122
120
 
123
- # Generates a unique file name.
121
+ # Generates a unique file name based on your default temporary directory,
122
+ # or whichever directory you specify.
124
123
  #
125
124
  # Note that a file is not actually generated on the filesystem.
126
125
  #--
127
126
  # NOTE: One quirk of the Windows function is that, after the first call, it
128
127
  # adds a file extension of sequential numbers in base 32, e.g. .1-.1vvvvvu.
129
128
  #
130
- def self.temp_name
129
+ def self.temp_name(directory: TMPDIR)
131
130
  ptr = FFI::MemoryPointer.new(:char, 1024)
132
131
  errno = tmpnam_s(ptr, ptr.size)
133
132
 
134
133
  raise SystemCallError.new('tmpnam_s', errno) if errno != 0
135
134
 
136
- TMPDIR + ptr.read_string + 'tmp'
135
+ directory + ptr.read_string + 'tmp'
137
136
  end
138
137
 
139
138
  private
@@ -22,7 +22,7 @@ class TC_File_Temp < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  test "library version is set to expected value" do
25
- assert_equal('1.4.0', File::Temp::VERSION)
25
+ assert_equal('1.5.0', File::Temp::VERSION)
26
26
  assert_true(File::Temp::VERSION.frozen?)
27
27
  end
28
28
 
@@ -48,33 +48,33 @@ class TC_File_Temp < Test::Unit::TestCase
48
48
 
49
49
  test "constructor works as expected with false auto delete option" do
50
50
  assert_nothing_raised{
51
- @fh = File::Temp.new(false)
51
+ @fh = File::Temp.new(:delete => false)
52
52
  @fh.print "hello"
53
53
  @fh.close
54
54
  }
55
55
  end
56
56
 
57
57
  test "constructor accepts and uses an optional template as expected" do
58
- assert_nothing_raised{ File::Temp.new(false, 'temp_foo_XXXXXX').close }
58
+ assert_nothing_raised{ File::Temp.new(:delete => false, :template => 'temp_foo_XXXXXX').close }
59
59
  assert_true(Dir["#{@dir}/temp_foo*"].length >= 1)
60
60
  end
61
61
 
62
62
  test "constructor with false auto delete and block works as expected" do
63
- assert_nothing_raised{ File::Temp.open(false, 'temp_foo_XXXXXX'){ |fh| fh.puts "hello" } }
63
+ assert_nothing_raised{ File::Temp.open(:delete => false, :template => 'temp_foo_XXXXXX'){ |fh| fh.puts "hello" } }
64
64
  assert_true(Dir["#{@dir}/temp_foo*"].length >= 1)
65
65
  end
66
66
 
67
- test "second argument to constructor must be a string" do
68
- assert_raise(TypeError, ArgumentError){ @fh = File::Temp.new(false, 1) }
67
+ test "template argument must be a string" do
68
+ assert_raise(TypeError, ArgumentError){ @fh = File::Temp.new(:delete => false, :template => 1) }
69
69
  end
70
70
 
71
71
  test "an error is raised if a custom template is invalid" do
72
72
  omit_if(OSX)
73
- assert_raise(Errno::EINVAL){ File::Temp.new(false, 'xx') }
73
+ assert_raise(Errno::EINVAL){ File::Temp.new(:delete => false, :template => 'xx') }
74
74
  end
75
75
 
76
- test "constructor accepts a maximum of two arguments" do
77
- assert_raise(ArgumentError){ @fh = File::Temp.new(true, 'temp_bar_XXXXX', 1) }
76
+ test "constructor accepts a maximum of three arguments" do
77
+ assert_raise(ArgumentError){ @fh = File::Temp.new(:delete => true, :template => 'temp_bar_XXXXX', :directory => Dir.pwd, :bogus => 1) }
78
78
  end
79
79
 
80
80
  test "temp_name basic functionality" do
@@ -102,7 +102,7 @@ class TC_File_Temp < Test::Unit::TestCase
102
102
  end
103
103
 
104
104
  test "temp path is not nil if delete option is false" do
105
- @fh = File::Temp.new(false)
105
+ @fh = File::Temp.new(delete: false)
106
106
  assert_not_nil(@fh.path)
107
107
  end
108
108
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-temp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -87,16 +87,14 @@ email: djberg96@gmail.com
87
87
  executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files:
90
- - CHANGES
91
- - README
92
- - MANIFEST
90
+ - CHANGES.rdoc
91
+ - README.rdoc
92
+ - MANIFEST.rdoc
93
93
  files:
94
+ - LICENSE
94
95
  - test
95
96
  - test/test_file_temp.rb
96
97
  - file-temp.gemspec
97
- - CHANGES
98
- - MANIFEST
99
- - README
100
98
  - Rakefile
101
99
  - certs
102
100
  - certs/djberg96_pub.pem
@@ -110,6 +108,9 @@ files:
110
108
  - lib/file/unix/temp.rb
111
109
  - lib/file/windows
112
110
  - lib/file/windows/temp.rb
111
+ - CHANGES.rdoc
112
+ - MANIFEST.rdoc
113
+ - README.rdoc
113
114
  homepage: http://github.com/djberg96/file-temp
114
115
  licenses:
115
116
  - Apache-2.0
@@ -135,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  - !ruby/object:Gem::Version
136
137
  version: '0'
137
138
  requirements: []
138
- rubygems_version: 3.0.6
139
+ rubygems_version: 3.0.3
139
140
  signing_key:
140
141
  specification_version: 4
141
142
  summary: An alternative way to generate temp files
metadata.gz.sig CHANGED
Binary file
data/README DELETED
@@ -1,65 +0,0 @@
1
- == Description
2
- The file-temp library is an alternate way to handle tempfile generation.
3
-
4
- == Requirements
5
- ffi 1.0.0 or later
6
-
7
- == Installation
8
- gem install file-temp
9
-
10
- == Synopsis
11
- require 'file/temp'
12
-
13
- fh = File::Temp.new
14
- fh.puts "hello"
15
- fh.close # => Tempfile automatically deleted
16
-
17
- fh = File::Temp.new(false)
18
- fh.puts "world"
19
- fh.close # => Tempfile still on your filesystem
20
-
21
- == Motivation
22
- Ruby's tempfile.rb is overwrought and susceptible to race conditions.
23
- This library uses your system's native tmpfile() or mkstemp() functions
24
- instead of trying to handle race conditions manually via pure Ruby.
25
-
26
- This library is also more secure because it restricts file permission via
27
- umask() for files created with mkstemp().
28
-
29
- Finally, this library subclasses the File class. This means you get almost
30
- exactly the same interface as the File class. The only difference is the
31
- constructor.
32
-
33
- == JRuby
34
- The implementation for JRuby uses the Java API, not the C API. The
35
- temporary file name generated by Java is different than the C version,
36
- since it uses a GUID instead of the 'XXXXXX' template, but the
37
- interface is otherwise identical.
38
-
39
- There is one test failure with JRuby (threaded tempfile creation). I am
40
- not sure why, as sample code seems to work fine. Help wanted.
41
-
42
- == MS Windows
43
- You may need to use the mingw build in order to use this library.
44
-
45
- Also, there was a bug with GetTempFileName function on certain versions
46
- of MS Windows that may cause a failure. However, if you'r patched up you
47
- should not see it.
48
-
49
- == License
50
- Artistic 2.0
51
-
52
- == Copyright
53
- (C) 2007-2016 Daniel J. Berger
54
- All Rights Reserved
55
-
56
- == Warranty
57
- This library is provided "as is" and without any express or
58
- implied warranties, including, without limitation, the implied
59
- warranties of merchantability and fitness for a particular purpose.
60
-
61
- == Author
62
- Daniel J. Berger
63
-
64
- == See also
65
- tmpfile(), mkstemp(), tmpnam()