fspath 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/fspath.gemspec +1 -1
- data/lib/fspath.rb +5 -1
- data/spec/fspath_spec.rb +7 -0
- metadata +4 -4
data/fspath.gemspec
CHANGED
data/lib/fspath.rb
CHANGED
@@ -36,13 +36,17 @@ class FSPath < Pathname
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Returns or yields path as FSPath of temp file created by Tempfile.new
|
39
|
+
# WARNING: loosing reference to returned object will remove file on nearest GC run
|
39
40
|
def temp_file_path(*args)
|
40
41
|
if block_given?
|
41
42
|
temp_file(*args) do |file|
|
42
43
|
yield file.path
|
43
44
|
end
|
44
45
|
else
|
45
|
-
temp_file(*args)
|
46
|
+
file = temp_file(*args)
|
47
|
+
path = file.path
|
48
|
+
path.instance_variable_set(:@__temp_file, file)
|
49
|
+
path
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
data/spec/fspath_spec.rb
CHANGED
@@ -57,6 +57,13 @@ describe FSPath do
|
|
57
57
|
klass.temp_file_path.should be_kind_of(klass)
|
58
58
|
end
|
59
59
|
|
60
|
+
it "should not allow GC to finalize TempFile" do
|
61
|
+
paths = Array.new(100){ FSPath.temp_file_path }
|
62
|
+
paths.should be_all(&:exist?)
|
63
|
+
GC.start
|
64
|
+
paths.should be_all(&:exist?)
|
65
|
+
end
|
66
|
+
|
60
67
|
it "should yield #{klass} with temporary path" do
|
61
68
|
yielded = nil
|
62
69
|
klass.temp_file_path{ |y| yielded = y }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fspath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ivan Kuchin
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|