fspath 3.0.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +15 -17
- data/Gemfile +4 -0
- data/README.markdown +4 -0
- data/fspath.gemspec +1 -1
- data/lib/fspath.rb +41 -9
- data/spec/fspath_spec.rb +109 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24453324aa20066ac43d90e423d410d039b3a6c5
|
4
|
+
data.tar.gz: ada2095a627c2435835da929aa502d68d73f3873
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6504c1b0e7e3e17d41938bc77a8c90f0736bacbcbf7ce004fcb70a17ab030c751d58031177d1cc5010c5d401424282e5a2bd0f9f0f5ef080affa69576cdd37a8
|
7
|
+
data.tar.gz: eb41f49e89b0f9d4b41501aca5b2752597cea4014dec67f7e126479e7f3f4c8c83539091773e276e3d286f80eaefdbc94f5da75e7d90b524543ca162371dc953
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -3,24 +3,22 @@ language: ruby
|
|
3
3
|
before_install:
|
4
4
|
- if [[ $TRAVIS_RUBY_VERSION =~ ^2\.[34] ]]; then gem update --system; fi
|
5
5
|
rvm:
|
6
|
-
- '1.8'
|
7
|
-
- '1.9'
|
8
|
-
- '2.0'
|
9
|
-
- '2.1'
|
10
|
-
- '2.2'
|
6
|
+
- '1.8.7-p371'
|
7
|
+
- '1.9.3-p551'
|
8
|
+
- '2.0.0-p648'
|
9
|
+
- '2.1.10'
|
10
|
+
- '2.2.6'
|
11
11
|
- '2.3.3'
|
12
12
|
- '2.4.0'
|
13
|
-
- jruby-
|
14
|
-
- jruby-
|
15
|
-
-
|
16
|
-
script:
|
17
|
-
if [ -n "$RUBOCOP" ]; then
|
18
|
-
bundle exec rubocop
|
19
|
-
; else
|
20
|
-
bundle exec rspec
|
21
|
-
; fi
|
13
|
+
- 'jruby-1.7.26'
|
14
|
+
- 'jruby-9.0.5.0'
|
15
|
+
- 'jruby-9.1.5.0'
|
16
|
+
script: bundle exec rspec
|
22
17
|
matrix:
|
23
|
-
fast_finish: true
|
24
18
|
include:
|
25
|
-
- env: RUBOCOP
|
26
|
-
rvm: '2'
|
19
|
+
- env: RUBOCOP=✓
|
20
|
+
rvm: '2.4.0'
|
21
|
+
script: bundle exec rubocop
|
22
|
+
- env: CHECK_RUBIES=✓
|
23
|
+
rvm: '2.4.0'
|
24
|
+
script: bundle exec travis_check_rubies
|
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -84,6 +84,10 @@ Path parts:
|
|
84
84
|
|
85
85
|
FSPath('/a/b/c').parts # => ['/', 'a', 'b', 'c']
|
86
86
|
|
87
|
+
Basename and extension:
|
88
|
+
|
89
|
+
FSPath('some/dir/name.ext').prefix_suffix # => [FSPath('name'), '.ext']
|
90
|
+
|
87
91
|
## Copyright
|
88
92
|
|
89
93
|
Copyright (c) 2010-2017 Ivan Kuchin. See LICENSE.txt for details.
|
data/fspath.gemspec
CHANGED
data/lib/fspath.rb
CHANGED
@@ -55,22 +55,22 @@ class FSPath < Pathname
|
|
55
55
|
|
56
56
|
# Returns or yields temp file created by Tempfile.new with path returning
|
57
57
|
# FSPath
|
58
|
-
def temp_file(*args, &block)
|
59
|
-
|
60
|
-
Tempfile.open(self, *args, &block)
|
58
|
+
def temp_file(prefix_suffix = nil, *args, &block)
|
59
|
+
prefix_suffix = fix_prefix_suffix(prefix_suffix || 'f')
|
60
|
+
Tempfile.open(self, prefix_suffix, *args, &block)
|
61
61
|
end
|
62
62
|
|
63
63
|
# Returns or yields path as FSPath of temp file created by Tempfile.new
|
64
64
|
# WARNING: loosing reference to returned object will remove file on nearest
|
65
65
|
# GC run
|
66
|
-
def temp_file_path(*args)
|
66
|
+
def temp_file_path(prefix_suffix = nil, *args)
|
67
67
|
if block_given?
|
68
|
-
temp_file(*args) do |file|
|
68
|
+
temp_file(prefix_suffix, *args) do |file|
|
69
69
|
file.close
|
70
70
|
yield file.path
|
71
71
|
end
|
72
72
|
else
|
73
|
-
file = temp_file(*args)
|
73
|
+
file = temp_file(prefix_suffix, *args)
|
74
74
|
file.close
|
75
75
|
path = file.path
|
76
76
|
path.instance_variable_set(:@__temp_file, file)
|
@@ -79,13 +79,24 @@ class FSPath < Pathname
|
|
79
79
|
end
|
80
80
|
|
81
81
|
# Returns or yields FSPath with temp directory created by Dir.mktmpdir
|
82
|
-
def temp_dir(*args)
|
82
|
+
def temp_dir(prefix_suffix = nil, *args)
|
83
|
+
prefix_suffix = fix_prefix_suffix(prefix_suffix || 'd')
|
83
84
|
if block_given?
|
84
|
-
Dir.mktmpdir(*args) do |dir|
|
85
|
+
Dir.mktmpdir(prefix_suffix, *args) do |dir|
|
85
86
|
yield new(dir)
|
86
87
|
end
|
87
88
|
else
|
88
|
-
new(Dir.mktmpdir(*args))
|
89
|
+
new(Dir.mktmpdir(prefix_suffix, *args))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def fix_prefix_suffix(prefix_suffix)
|
96
|
+
if prefix_suffix.is_a?(Array)
|
97
|
+
prefix_suffix.map(&:to_s)
|
98
|
+
else
|
99
|
+
prefix_suffix.to_s
|
89
100
|
end
|
90
101
|
end
|
91
102
|
end
|
@@ -102,6 +113,27 @@ class FSPath < Pathname
|
|
102
113
|
end
|
103
114
|
end
|
104
115
|
|
116
|
+
# Return basename without ext and ext as two-element array
|
117
|
+
def prefix_suffix
|
118
|
+
ext = extname
|
119
|
+
[basename(ext), ext]
|
120
|
+
end
|
121
|
+
|
122
|
+
# Calls class method with prefix and suffix set using prefix_suffix
|
123
|
+
def temp_file(*args, &block)
|
124
|
+
self.class.temp_file(prefix_suffix, *args, &block)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Calls class method with prefix and suffix set using prefix_suffix
|
128
|
+
def temp_file_path(*args, &block)
|
129
|
+
self.class.temp_file_path(prefix_suffix, *args, &block)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Calls class method with prefix and suffix set using prefix_suffix
|
133
|
+
def temp_dir(*args, &block)
|
134
|
+
self.class.temp_dir(prefix_suffix, *args, &block)
|
135
|
+
end
|
136
|
+
|
105
137
|
# Fixing Pathname.relative_path_from
|
106
138
|
def relative_path_from(other)
|
107
139
|
self.class.new(super(self.class.new(other)))
|
data/spec/fspath_spec.rb
CHANGED
@@ -55,6 +55,28 @@ describe FSPath do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
shared_examples 'converts prefix_suffix' do |options|
|
59
|
+
it "passes default (#{options[:default].inspect}) without arguments" do
|
60
|
+
expect(result_path_for.basename.to_s).
|
61
|
+
to match(/^#{options[:default]}/)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'passes default when receives nil' do
|
65
|
+
expect(result_path_for(nil).basename.to_s).
|
66
|
+
to match(/^#{options[:default]}/)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'passes each member of Array converted to String' do
|
70
|
+
expect(result_path_for(FSPath('bar')).basename.to_s).
|
71
|
+
to match(/^bar/)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'passes non String converted to string' do
|
75
|
+
expect(result_path_for([FSPath('foo'), FSPath('.bar')]).basename.to_s).
|
76
|
+
to match(/^foo.*\.bar$/)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
58
80
|
describe '.temp_file' do
|
59
81
|
[FSPath, ZPath].each do |klass|
|
60
82
|
context "when called on #{klass}" do
|
@@ -81,6 +103,12 @@ describe FSPath do
|
|
81
103
|
FSPath.temp_file('abc', '.'){}
|
82
104
|
end.not_to raise_error
|
83
105
|
end
|
106
|
+
|
107
|
+
include_examples 'converts prefix_suffix', :default => 'f' do
|
108
|
+
def result_path_for(*args)
|
109
|
+
FSPath.temp_file(*args).path
|
110
|
+
end
|
111
|
+
end
|
84
112
|
end
|
85
113
|
|
86
114
|
describe '.temp_file_path' do
|
@@ -129,6 +157,12 @@ describe FSPath do
|
|
129
157
|
end
|
130
158
|
end
|
131
159
|
end
|
160
|
+
|
161
|
+
include_examples 'converts prefix_suffix', :default => 'f' do
|
162
|
+
def result_path_for(*args)
|
163
|
+
FSPath.temp_file_path(*args)
|
164
|
+
end
|
165
|
+
end
|
132
166
|
end
|
133
167
|
|
134
168
|
describe '.temp_dir' do
|
@@ -147,6 +181,12 @@ describe FSPath do
|
|
147
181
|
FSPath.temp_dir{ |y| yielded = y }
|
148
182
|
expect(yielded).to eq(FSPath('/tmp/a/b/2'))
|
149
183
|
end
|
184
|
+
|
185
|
+
include_examples 'converts prefix_suffix', :default => 'd' do
|
186
|
+
def result_path_for(*args)
|
187
|
+
FSPath.temp_dir(*args)
|
188
|
+
end
|
189
|
+
end
|
150
190
|
end
|
151
191
|
|
152
192
|
describe '#/' do
|
@@ -177,6 +217,75 @@ describe FSPath do
|
|
177
217
|
end
|
178
218
|
end
|
179
219
|
|
220
|
+
describe '#prefix_suffix' do
|
221
|
+
context 'when path has ext' do
|
222
|
+
it 'returns basename and ext' do
|
223
|
+
expect(FSPath('dir/name.foo').prefix_suffix).
|
224
|
+
to eq([FSPath('name'), '.foo'])
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context 'when path has multiple exts' do
|
229
|
+
it 'returns basename and last ext' do
|
230
|
+
expect(FSPath('dir/name.foo.bar').prefix_suffix).
|
231
|
+
to eq([FSPath('name.foo'), '.bar'])
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'when path has no ext' do
|
236
|
+
it 'returns basename and empty string' do
|
237
|
+
expect(FSPath('dir/just_name').prefix_suffix).
|
238
|
+
to eq([FSPath('just_name'), ''])
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context 'when path starts with dot and has ext' do
|
243
|
+
it 'returns basename and ext' do
|
244
|
+
expect(FSPath('dir/.name.foo').prefix_suffix).
|
245
|
+
to eq([FSPath('.name'), '.foo'])
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'when path starts with dot and has no ext' do
|
250
|
+
it 'returns basename and empty string' do
|
251
|
+
expect(FSPath('dir/.just_name').prefix_suffix).
|
252
|
+
to eq([FSPath('.just_name'), ''])
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe 'instance temp_* methods' do
|
258
|
+
let(:block){ proc{ 'x' } }
|
259
|
+
let(:args){ [[FSPath('path'), '.name'], FSPath('.')] }
|
260
|
+
|
261
|
+
describe '#temp_file' do
|
262
|
+
it 'calls class method with prefix_suffix as first argument' do
|
263
|
+
expect(FSPath).to receive(:temp_file).
|
264
|
+
with(*args){ |&b| expect(b).to be(block) }
|
265
|
+
|
266
|
+
FSPath('some/path.name').temp_file(FSPath('.'), &block)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
describe '#temp_file_path' do
|
271
|
+
it 'calls class method with prefix_suffix as first argument' do
|
272
|
+
expect(FSPath).to receive(:temp_file_path).
|
273
|
+
with(*args){ |&b| expect(b).to be(block) }
|
274
|
+
|
275
|
+
FSPath('some/path.name').temp_file_path(FSPath('.'), &block)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
describe '#temp_dir' do
|
280
|
+
it 'calls class method with prefix_suffix as first argument' do
|
281
|
+
expect(FSPath).to receive(:temp_dir).
|
282
|
+
with(*args){ |&b| expect(b).to be(block) }
|
283
|
+
|
284
|
+
FSPath('some/path.name').temp_dir(FSPath('.'), &block)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
180
289
|
describe '#relative_path_from' do
|
181
290
|
it 'returns instance of FSPath' do
|
182
291
|
expect(FSPath('a').relative_path_from('b')).to be_instance_of(FSPath)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fspath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kuchin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project: fspath
|
77
|
-
rubygems_version: 2.6.
|
77
|
+
rubygems_version: 2.6.10
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Better than Pathname
|