temppath 0.3.0 → 0.3.1
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.
- data/README.md +10 -3
- data/lib/temppath.rb +24 -3
- data/lib/temppath/version.rb +1 -1
- data/test/spec_temppath.rb +32 -5
- metadata +3 -3
data/README.md
CHANGED
@@ -7,6 +7,13 @@ deleted when Ruby exits.
|
|
7
7
|
|
8
8
|
[](http://badge.fury.io/rb/temppath) [](https://travis-ci.org/keita/temppath) [](https://coveralls.io/r/keita/temppath) [](https://codeclimate.com/github/keita/temppath)
|
9
9
|
|
10
|
+
## Features
|
11
|
+
|
12
|
+
* You can generate a path without file.
|
13
|
+
* Temppath can generate files and directories as well. Therefore you are free
|
14
|
+
from confusion which is correct tmpfile/tempfile or tmpdir/tempdir.
|
15
|
+
* Generated paths are `Pathname` objects.
|
16
|
+
|
10
17
|
## Installation
|
11
18
|
|
12
19
|
$ gem install temppath
|
@@ -43,9 +50,9 @@ path.file? #=> true
|
|
43
50
|
|
44
51
|
#### Use temporary path generator
|
45
52
|
|
46
|
-
You can use Temppath::Generator when you want to use multiple base
|
47
|
-
directory. Generated paths have same natures as paths from Tempath.create
|
48
|
-
mkdir
|
53
|
+
You can use `Temppath::Generator` when you want to use multiple base
|
54
|
+
directory. Generated paths have same natures as paths from `Tempath.create`,
|
55
|
+
`mkdir`, and `touch`.
|
49
56
|
|
50
57
|
```ruby
|
51
58
|
# make a generator
|
data/lib/temppath.rb
CHANGED
@@ -103,6 +103,10 @@ module Temppath
|
|
103
103
|
@basename = (option[:basename] || "").to_s
|
104
104
|
@unlink = true
|
105
105
|
|
106
|
+
# extend basedir with secure methods
|
107
|
+
@basedir.extend OriginalMethodHolder
|
108
|
+
@basedir.extend SecurePermissionMethods
|
109
|
+
|
106
110
|
# register a cleaner for temporary directory
|
107
111
|
Kernel.at_exit do
|
108
112
|
if @unlink
|
@@ -120,11 +124,18 @@ module Temppath
|
|
120
124
|
# pathname of base directory
|
121
125
|
def create(option={})
|
122
126
|
_basename = option[:basename] || @basename
|
123
|
-
_basedir =
|
127
|
+
_basedir = @basedir
|
128
|
+
if option[:basedir]
|
129
|
+
_basedir = Pathname.new(option[:basedir])
|
130
|
+
|
131
|
+
# extend basedir with secure methods
|
132
|
+
_basedir.extend OriginalMethodHolder
|
133
|
+
_basedir.extend SecurePermissionMethods
|
134
|
+
end
|
124
135
|
|
125
136
|
# init basedir
|
126
137
|
unless _basedir.exist?
|
127
|
-
_basedir.
|
138
|
+
_basedir.mkpath
|
128
139
|
end
|
129
140
|
|
130
141
|
# make a path
|
@@ -219,6 +230,16 @@ module Temppath
|
|
219
230
|
@generator.basedir
|
220
231
|
end
|
221
232
|
|
233
|
+
# Return base name of paths created by Temppath.
|
234
|
+
def basename
|
235
|
+
@generator.basename
|
236
|
+
end
|
237
|
+
|
238
|
+
# Set the base name.
|
239
|
+
def basename=(name)
|
240
|
+
@generator.basename = name
|
241
|
+
end
|
242
|
+
|
222
243
|
# Return true if unlink mode is enabled.
|
223
244
|
#
|
224
245
|
# @return [Boolean]
|
@@ -227,7 +248,7 @@ module Temppath
|
|
227
248
|
@generator.unlink
|
228
249
|
end
|
229
250
|
|
230
|
-
# Set true or false unlink mode.
|
251
|
+
# Set true or false for unlink mode.
|
231
252
|
#
|
232
253
|
# @param b [Boolean]
|
233
254
|
# unlink mode
|
data/lib/temppath/version.rb
CHANGED
data/test/spec_temppath.rb
CHANGED
@@ -47,6 +47,18 @@ describe Temppath do
|
|
47
47
|
dir.should.not.exist
|
48
48
|
end
|
49
49
|
|
50
|
+
it 'should get basename' do
|
51
|
+
Temppath.basename.should == ""
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should set basename' do
|
55
|
+
Temppath.basename = "test_"
|
56
|
+
Temppath.basename.should == "test_"
|
57
|
+
Temppath.create.basename.to_s.should.start_with "test_"
|
58
|
+
Temppath.basename = ""
|
59
|
+
Temppath.create.basename.to_s.should.not.start_with "test_"
|
60
|
+
end
|
61
|
+
|
50
62
|
it 'should get unlink mode' do
|
51
63
|
Temppath.unlink.should == true
|
52
64
|
end
|
@@ -122,7 +134,7 @@ describe Temppath::Generator do
|
|
122
134
|
before do
|
123
135
|
Temppath.update_basedir
|
124
136
|
@dir = Dir.mktmpdir("ruby-temppath-generator-test")
|
125
|
-
@generator = Temppath::Generator.new(@dir)
|
137
|
+
@generator = Temppath::Generator.new(@dir, basename: "test_")
|
126
138
|
end
|
127
139
|
|
128
140
|
it "should generate a path" do
|
@@ -151,13 +163,13 @@ describe Temppath::Generator do
|
|
151
163
|
it "should have own base directory" do
|
152
164
|
Temppath.basedir.should != @generator.basedir
|
153
165
|
|
154
|
-
dir = Dir.mktmpdir("ruby-temppath-generator-test")
|
166
|
+
dir = Pathname.new(Dir.mktmpdir("ruby-temppath-generator-test"))
|
155
167
|
generator = Temppath::Generator.new(dir)
|
156
168
|
generator.basedir.should != @generator.basedir
|
157
169
|
end
|
158
170
|
|
159
171
|
it "should make base directory with #create if it doesn't exist" do
|
160
|
-
dir = Dir.mktmpdir("ruby-temppath-generator-test")
|
172
|
+
dir = Pathname.new(Dir.mktmpdir("ruby-temppath-generator-test"))
|
161
173
|
generator = Temppath::Generator.new(dir + "create")
|
162
174
|
generator.basedir.should.not.exist
|
163
175
|
generator.create
|
@@ -165,7 +177,7 @@ describe Temppath::Generator do
|
|
165
177
|
end
|
166
178
|
|
167
179
|
it "should make base directory with #mkdir if it doesn't exist" do
|
168
|
-
dir = Dir.mktmpdir("ruby-temppath-generator-test")
|
180
|
+
dir = Pathname.new(Dir.mktmpdir("ruby-temppath-generator-test"))
|
169
181
|
generator = Temppath::Generator.new(dir + "mkdir")
|
170
182
|
generator.basedir.should.not.exist
|
171
183
|
generator.create
|
@@ -173,10 +185,25 @@ describe Temppath::Generator do
|
|
173
185
|
end
|
174
186
|
|
175
187
|
it "should make base directory with #touch if it doesn't exist" do
|
176
|
-
dir = Dir.mktmpdir("ruby-temppath-generator-test")
|
188
|
+
dir = Pathname.new(Dir.mktmpdir("ruby-temppath-generator-test"))
|
177
189
|
generator = Temppath::Generator.new(dir + "touch")
|
178
190
|
generator.basedir.should.not.exist
|
179
191
|
generator.create
|
180
192
|
generator.basedir.should.exist
|
181
193
|
end
|
194
|
+
|
195
|
+
it "should make base directory and parents" do
|
196
|
+
dir = Pathname.new(Dir.mktmpdir("ruby-temppath-generator-test"))
|
197
|
+
generator = Temppath::Generator.new(dir + "a" + "b" + "c")
|
198
|
+
generator.basedir.should.not.exist
|
199
|
+
path = generator.create
|
200
|
+
generator.basedir.should.exist
|
201
|
+
("%o" % (dir + "a").stat.mode).should == "40700"
|
202
|
+
("%o" % (dir + "a" + "b").stat.mode).should == "40700"
|
203
|
+
("%o" % (dir + "a" + "b" + "c").stat.mode).should == "40700"
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should make path with generator's basename" do
|
207
|
+
@generator.create.basename.to_s.should.start_with "test_"
|
208
|
+
end
|
182
209
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: temppath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
segments:
|
125
125
|
- 0
|
126
|
-
hash:
|
126
|
+
hash: -400379893233300288
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
segments:
|
134
134
|
- 0
|
135
|
-
hash:
|
135
|
+
hash: -400379893233300288
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
138
|
rubygems_version: 1.8.25
|