fspath 2.0.6 → 2.1.0
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.
- checksums.yaml +8 -8
- data/.travis.yml +0 -2
- data/README.markdown +2 -0
- data/fspath.gemspec +1 -1
- data/lib/fspath.rb +112 -18
- data/spec/fspath_spec.rb +158 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWMyZGJiOTM2MzZkOWQwZTljNjE4Yjc3MmI5MTAxOTliNDU0OTdmZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWFkODdkNTRlOTQyYjFmZDVkYjZhM2JjM2VmZTQ2NWZjZGViMzliYw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGVhNmZhYTZjODQzNWYzMzA0OGNkOGRjNjhmNmQyNWYzNDQyMWU3ZThjNDE5
|
10
|
+
MmJmYzc5NTI0NGFlYTE5ZjgxMzE1N2Y2ZDhjOTJiYmJjZjUxNzc4ODA1ZWFi
|
11
|
+
ZGJmN2U4ZjEwM2ExYTk0ZGFhMzJhOWVjYmEyZDZkYjRhMjc2YTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWU5Yjc2OGViYjkwMDNhNzE4MDNiMjUwZjkzZmY5NTFhYjFkYWQ2Y2RkNGRm
|
14
|
+
MjM5ODE3ODE3ZmI4OGVhZjc1MzI0NmFlNGE1YTdmM2Q0ZWRkNzc2ODg0ZTM3
|
15
|
+
OTI2Y2Q4ZTgyMDRhOTcxOTJkY2E0YzkwOWE1Y2UyZTYwNzBmZmU=
|
data/.travis.yml
CHANGED
data/README.markdown
CHANGED
@@ -42,10 +42,12 @@ Expand glob:
|
|
42
42
|
|
43
43
|
Ascendants:
|
44
44
|
|
45
|
+
FSPath('a/b/c').ascendants
|
45
46
|
FSPath('a/b/c').ascend # => [FSPath('a/b/c'), FSPath('a/b'), FSPath('a')]
|
46
47
|
|
47
48
|
Descendants:
|
48
49
|
|
50
|
+
FSPath('a/b/c').descendants
|
49
51
|
FSPath('a/b/c').descend # => [FSPath('a'), FSPath('a/b'), FSPath('a/b/c')]
|
50
52
|
|
51
53
|
Path parts:
|
data/fspath.gemspec
CHANGED
data/lib/fspath.rb
CHANGED
@@ -39,7 +39,7 @@ class FSPath < Pathname
|
|
39
39
|
# Returns common dir for paths
|
40
40
|
def common_dir(*paths)
|
41
41
|
paths.map do |path|
|
42
|
-
new(path).
|
42
|
+
new(path).ascendants.drop(1)
|
43
43
|
end.inject(:&).first
|
44
44
|
end
|
45
45
|
|
@@ -83,9 +83,9 @@ class FSPath < Pathname
|
|
83
83
|
end
|
84
84
|
|
85
85
|
unless (new('a') + 'b').is_a?(self)
|
86
|
-
# Fixing Pathname
|
86
|
+
# Fixing Pathname#+
|
87
87
|
def +(other)
|
88
|
-
self.class.new(
|
88
|
+
self.class.new(super)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -121,36 +121,130 @@ class FSPath < Pathname
|
|
121
121
|
self.class.glob(*args, &block)
|
122
122
|
end
|
123
123
|
|
124
|
-
#
|
125
|
-
def
|
126
|
-
|
124
|
+
# Returns list of elements in the given path in ascending order
|
125
|
+
def ascendants
|
126
|
+
paths = []
|
127
127
|
path = @path
|
128
|
-
|
128
|
+
paths << self
|
129
129
|
while r = chop_basename(path)
|
130
130
|
path, name = r
|
131
131
|
break if path.empty?
|
132
|
-
|
133
|
-
end
|
134
|
-
if block
|
135
|
-
ascendants.each(&block)
|
132
|
+
paths << self.class.new(del_trailing_separator(path))
|
136
133
|
end
|
137
|
-
|
134
|
+
paths
|
135
|
+
end
|
136
|
+
|
137
|
+
# Returns list of elements in the given path in descending order
|
138
|
+
def descendants
|
139
|
+
ascendants.reverse
|
140
|
+
end
|
141
|
+
|
142
|
+
# Iterates over and yields each element in the given path in ascending order
|
143
|
+
def ascend(&block)
|
144
|
+
paths = ascendants
|
145
|
+
paths.each(&block) if block
|
146
|
+
paths
|
138
147
|
end
|
139
148
|
|
140
149
|
# Iterates over and yields each element in the given path in descending order
|
141
150
|
def descend(&block)
|
142
|
-
|
143
|
-
if block
|
144
|
-
|
145
|
-
end
|
146
|
-
descendants
|
151
|
+
paths = descendants
|
152
|
+
paths.each(&block) if block
|
153
|
+
paths
|
147
154
|
end
|
148
155
|
|
149
156
|
# Returns path parts
|
150
|
-
def parts
|
157
|
+
def parts
|
151
158
|
split_names(@path).flatten
|
152
159
|
end
|
153
160
|
|
161
|
+
unless new('a').basename.is_a?(self)
|
162
|
+
# Fixing glob
|
163
|
+
def self.glob(*args)
|
164
|
+
if block_given?
|
165
|
+
super{ |f| yield new(f) }
|
166
|
+
else
|
167
|
+
super.map{ |f| new(f) }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# Fixing getwd
|
172
|
+
def self.getwd
|
173
|
+
new(super)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Fixing pwd
|
177
|
+
def self.pwd
|
178
|
+
new(super)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Fixing basename
|
182
|
+
def basename(*args)
|
183
|
+
self.class.new(super)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Fixing dirname
|
187
|
+
def dirname
|
188
|
+
self.class.new(super)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Fixing expand_path
|
192
|
+
def expand_path(*args)
|
193
|
+
self.class.new(super)
|
194
|
+
end
|
195
|
+
|
196
|
+
# Fixing split
|
197
|
+
def split
|
198
|
+
super.map{ |f| self.class.new(f) }
|
199
|
+
end
|
200
|
+
|
201
|
+
# Fixing sub
|
202
|
+
def sub(pattern, *rest, &block)
|
203
|
+
self.class.new(super)
|
204
|
+
end
|
205
|
+
|
206
|
+
if Pathname.method_defined?(:sub_ext)
|
207
|
+
# Fixing sub_ext
|
208
|
+
def sub_ext(ext)
|
209
|
+
self.class.new(super)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
# Fixing realpath
|
214
|
+
def realpath
|
215
|
+
self.class.new(super)
|
216
|
+
end
|
217
|
+
|
218
|
+
if Pathname.method_defined?(:realdirpath)
|
219
|
+
# Fixing realdirpath
|
220
|
+
def realdirpath
|
221
|
+
self.class.new(super)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
# Fixing readlink
|
226
|
+
def readlink
|
227
|
+
self.class.new(super)
|
228
|
+
end
|
229
|
+
|
230
|
+
# Fixing each_entry
|
231
|
+
def each_entry
|
232
|
+
super{ |f| yield self.class.new(f) }
|
233
|
+
end
|
234
|
+
|
235
|
+
# Fixing entries
|
236
|
+
def entries
|
237
|
+
super.map{ |f| self.class.new(f) }
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
unless new('a').inspect.include?('FSPath')
|
242
|
+
# Fixing inspect
|
243
|
+
def inspect
|
244
|
+
"#<#{self.class}:#{@path}>"
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
154
248
|
private
|
155
249
|
|
156
250
|
def escape_glob_string
|
data/spec/fspath_spec.rb
CHANGED
@@ -208,41 +208,57 @@ describe FSPath do
|
|
208
208
|
end
|
209
209
|
|
210
210
|
describe "path parts" do
|
211
|
-
describe "
|
211
|
+
describe "ascending" do
|
212
212
|
before do
|
213
213
|
@path = FSPath('/a/b/c')
|
214
214
|
@ascendants = %w[/a/b/c /a/b /a /].map(&method(:FSPath))
|
215
215
|
end
|
216
216
|
|
217
|
-
|
218
|
-
|
217
|
+
describe "ascendants" do
|
218
|
+
it "should return list of ascendants" do
|
219
|
+
@path.ascendants.should == @ascendants
|
220
|
+
end
|
219
221
|
end
|
220
222
|
|
221
|
-
|
222
|
-
ascendants
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
223
|
+
describe "ascend" do
|
224
|
+
it "should return list of ascendants" do
|
225
|
+
@path.ascend.should == @ascendants
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should yield and return list of ascendants if called with block" do
|
229
|
+
ascendants = []
|
230
|
+
@path.ascend do |path|
|
231
|
+
ascendants << path
|
232
|
+
end.should == @ascendants
|
233
|
+
ascendants.should == @ascendants
|
234
|
+
end
|
227
235
|
end
|
228
236
|
end
|
229
237
|
|
230
|
-
describe "
|
238
|
+
describe "descending" do
|
231
239
|
before do
|
232
240
|
@path = FSPath('/a/b/c')
|
233
241
|
@descendants = %w[/ /a /a/b /a/b/c].map(&method(:FSPath))
|
234
242
|
end
|
235
243
|
|
236
|
-
|
237
|
-
|
244
|
+
describe "descendants" do
|
245
|
+
it "should return list of descendants" do
|
246
|
+
@path.descendants.should == @descendants
|
247
|
+
end
|
238
248
|
end
|
239
249
|
|
240
|
-
|
241
|
-
descendants
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
250
|
+
describe "descend" do
|
251
|
+
it "should return list of descendants" do
|
252
|
+
@path.descend.should == @descendants
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should yield and return list of descendants if called with block" do
|
256
|
+
descendants = []
|
257
|
+
@path.descend do |path|
|
258
|
+
descendants << path
|
259
|
+
end.should == @descendants
|
260
|
+
descendants.should == @descendants
|
261
|
+
end
|
246
262
|
end
|
247
263
|
end
|
248
264
|
|
@@ -252,4 +268,128 @@ describe FSPath do
|
|
252
268
|
end
|
253
269
|
end
|
254
270
|
end
|
271
|
+
|
272
|
+
describe "returning/yield instances of FSPath" do
|
273
|
+
def fspath?(path)
|
274
|
+
path.should be_instance_of(FSPath)
|
275
|
+
end
|
276
|
+
|
277
|
+
def fspaths?(paths)
|
278
|
+
paths.each do |path|
|
279
|
+
fspath? path
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should for glob" do
|
284
|
+
fspaths? FSPath(__FILE__).glob
|
285
|
+
|
286
|
+
FSPath(__FILE__).glob do |path|
|
287
|
+
fspath? path
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should for pwd" do
|
292
|
+
fspath? FSPath.pwd
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should for getwd" do
|
296
|
+
fspath? FSPath.getwd
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should for basename" do
|
300
|
+
fspath? FSPath('a/b').basename
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should for dirname" do
|
304
|
+
fspath? FSPath('a/b').dirname
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should for parent" do
|
308
|
+
fspath? FSPath('a/b').parent
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should for cleanpath" do
|
312
|
+
fspath? FSPath('a/b').cleanpath
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should for expand_path" do
|
316
|
+
fspath? FSPath('a/b').expand_path
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should for relative_path_from" do
|
320
|
+
fspath? FSPath('a').relative_path_from('b')
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should for join" do
|
324
|
+
fspath? FSPath('a').join('b', 'c')
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should for split" do
|
328
|
+
fspaths? FSPath('a/b').split
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should for sub" do
|
332
|
+
fspath? FSPath('a/b').sub('a', 'c')
|
333
|
+
fspath? FSPath('a/b').sub('a'){ 'c' }
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should for sub_ext" do
|
337
|
+
fspath? FSPath('a/b').sub_ext('.rb')
|
338
|
+
end if FSPath.method_defined?(:sub_ext)
|
339
|
+
|
340
|
+
it "should for readlink" do
|
341
|
+
FSPath.temp_dir do |dir|
|
342
|
+
symlink = dir + 'sym'
|
343
|
+
symlink.make_symlink __FILE__
|
344
|
+
fspath? symlink.readlink
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
it "should for realdirpath" do
|
349
|
+
fspath? FSPath(__FILE__).realdirpath
|
350
|
+
end if FSPath.method_defined?(:realdirpath)
|
351
|
+
|
352
|
+
it "should for realpath" do
|
353
|
+
fspath? FSPath(__FILE__).realpath
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should for children" do
|
357
|
+
fspaths? FSPath('.').children
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should for dir_foreach" do
|
361
|
+
dir = FSPath('.')
|
362
|
+
dir.stub(:warn)
|
363
|
+
dir.dir_foreach do |entry|
|
364
|
+
fspath? entry
|
365
|
+
end
|
366
|
+
end if FSPath.method_defined?(:dir_foreach)
|
367
|
+
|
368
|
+
it "should for each_child" do
|
369
|
+
fspaths? FSPath('.').each_child
|
370
|
+
fspaths? FSPath('.').each_child do |child|
|
371
|
+
fspath? child
|
372
|
+
end
|
373
|
+
end if FSPath.method_defined?(:each_child)
|
374
|
+
|
375
|
+
it "should for each_entry" do
|
376
|
+
FSPath('.').each_entry do |entry|
|
377
|
+
fspath? entry
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
it "should for entries" do
|
382
|
+
fspaths? FSPath('.').entries
|
383
|
+
end
|
384
|
+
|
385
|
+
it "should for find" do
|
386
|
+
FSPath('.').find do |path|
|
387
|
+
fspath? path
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
it "should for inspect" do
|
392
|
+
FSPath('a').inspect.should include('FSPath')
|
393
|
+
end
|
394
|
+
end
|
255
395
|
end
|
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: 2.0
|
4
|
+
version: 2.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: 2013-12-
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|