pathname2 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/README +7 -18
- data/lib/pathname2.rb +217 -35
- data/test/test_pathname.rb +6 -5
- data/test/test_pathname_windows.rb +24 -4
- metadata +3 -5
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 1.6.1 - 8-Nov-2008
|
2
|
+
* Added the Pathname#[] method, which accepts an index, an index plus a
|
3
|
+
length, or a range, and returns appropriate the path element(s).
|
4
|
+
* Refactoring the platform checking in the test suite to use rbconfig instead
|
5
|
+
of RUBY_PLATFORM.
|
6
|
+
* More inline documentation examples.
|
7
|
+
|
1
8
|
== 1.6.0 - 13-July-2008
|
2
9
|
* The facade for ftools (and ftools itself) has been removed. The ftools
|
3
10
|
library is deprecated in favor of FileUtils.
|
data/README
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
* facade 1.0.0 or later (available on the RAA and as a gem)
|
7
7
|
* windows-pr 0.5.1 or later (available on the RAA and as a gem)
|
8
8
|
|
9
|
-
The windows-pr
|
9
|
+
The windows-pr library is only required on MS Windows.
|
10
10
|
|
11
11
|
== Installation, pure Ruby
|
12
12
|
=== Manual Installation
|
@@ -67,15 +67,9 @@
|
|
67
67
|
Pathname#clean("../a") returns "../a". In this version, it returns "a".
|
68
68
|
This affects other methods, such as Pathname#relative_path_from.
|
69
69
|
* Accepts file urls and converts them to paths automatically, e.g.
|
70
|
-
file:///foo%20bar/baz becomes '/foo
|
70
|
+
file:///foo%20bar/baz becomes '/foo/bar/baz'.
|
71
71
|
* Adds a Kernel level +pn+ method as a shortcut.
|
72
72
|
* Allows you to add paths together with the '/' operator.
|
73
|
-
|
74
|
-
== Differences between Unix platforms - C version
|
75
|
-
* On BSD systems, including OS X, the Pathname#realpath() method requires
|
76
|
-
that all components of a path *except the last* actually exist. Other
|
77
|
-
platforms require that the *entire* path actually exist. This is the
|
78
|
-
way the underlying realpath() C function works on these systems.
|
79
73
|
|
80
74
|
== Method Priority
|
81
75
|
Because there is some overlap in method names between File, Dir, and
|
@@ -86,19 +80,15 @@
|
|
86
80
|
* FileUtils
|
87
81
|
|
88
82
|
In other words, whichever of these defines a given method first is the
|
89
|
-
method that is used by the pathname2
|
83
|
+
method that is used by the pathname2 library.
|
90
84
|
|
91
85
|
== Known Issues
|
92
|
-
You cannot pass a frozen string to the constructor on Windows using the
|
93
|
-
pure Ruby version. There is an unresolved issue with Win32API and frozen
|
94
|
-
objects.
|
95
|
-
|
96
|
-
Pathname#glob is not yet implemented in the C version.
|
97
|
-
Pathname#find is not implemented properly in the C version.
|
98
|
-
|
99
86
|
In Ruby 1.8.3 and 1.8.4 you will see a failure in the test suite regarding
|
100
87
|
'fu_world_writable?' from FileUtils. You can ignore this. That method is
|
101
88
|
supposed to be private. See ruby-core:7383.
|
89
|
+
|
90
|
+
Any other issues should be reported on the project page at
|
91
|
+
http://www.rubyforge.org/projects/shards
|
102
92
|
|
103
93
|
== Future Plans
|
104
94
|
Suggestions welcome.
|
@@ -107,11 +97,10 @@
|
|
107
97
|
Ruby's
|
108
98
|
|
109
99
|
== Warranty
|
110
|
-
This
|
100
|
+
This library is provided "as is" and without any express or
|
111
101
|
implied warranties, including, without limitation, the implied
|
112
102
|
warranties of merchantability and fitness for a particular purpose.
|
113
103
|
|
114
104
|
== Author
|
115
105
|
Daniel J. Berger
|
116
106
|
djberg96 at gmail dot com
|
117
|
-
imperator on IRC (irc.freenode.net)
|
data/lib/pathname2.rb
CHANGED
@@ -60,6 +60,8 @@ class Pathname < String
|
|
60
60
|
|
61
61
|
facade Dir, Dir.methods(false) - ['chdir','glob','foreach','mkdir','open']
|
62
62
|
|
63
|
+
private
|
64
|
+
|
63
65
|
alias :_plus_ :+ # Used to prevent infinite loops in some cases
|
64
66
|
|
65
67
|
if Config::CONFIG['host_os'].match('mswin')
|
@@ -68,9 +70,14 @@ class Pathname < String
|
|
68
70
|
include Windows::Error
|
69
71
|
include Windows::Limits
|
70
72
|
end
|
73
|
+
|
74
|
+
public
|
71
75
|
|
72
|
-
VERSION = '1.6.
|
73
|
-
|
76
|
+
VERSION = '1.6.1'
|
77
|
+
|
78
|
+
if !defined? MAXPATH
|
79
|
+
MAXPATH = 1024
|
80
|
+
end
|
74
81
|
|
75
82
|
# Creates and returns a new Pathname object.
|
76
83
|
#
|
@@ -82,6 +89,13 @@ class Pathname < String
|
|
82
89
|
# "file:///C:/Documents%20and%20Settings" will become
|
83
90
|
# 'C:\Documents and Settings'.
|
84
91
|
#
|
92
|
+
# Examples:
|
93
|
+
#
|
94
|
+
# Pathname.new("/foo/bar/baz"
|
95
|
+
# Pathname.new("foo")
|
96
|
+
# Pathname.new("file:///foo/bar/baz")
|
97
|
+
# Pathname.new("C:\\Documents and Settings\\snoopy")
|
98
|
+
#
|
85
99
|
def initialize(path)
|
86
100
|
if path.length > MAXPATH
|
87
101
|
msg = "string too long. maximum string length is " + MAXPATH.to_s
|
@@ -122,6 +136,12 @@ class Pathname < String
|
|
122
136
|
# exists on your filesystem. If it doesn't, an error is raised. If a
|
123
137
|
# circular symlink is encountered a system error will be raised.
|
124
138
|
#
|
139
|
+
# Example:
|
140
|
+
#
|
141
|
+
# Dir.pwd # => /usr/local
|
142
|
+
# File.exists?('foo') # => true
|
143
|
+
# Pathname.new('foo').realpath # => /usr/local/foo
|
144
|
+
#
|
125
145
|
def realpath
|
126
146
|
File.stat(self) # Check to ensure that the path exists
|
127
147
|
|
@@ -147,6 +167,12 @@ class Pathname < String
|
|
147
167
|
# the directory because they are not children. Also note that this method
|
148
168
|
# is *not* recursive.
|
149
169
|
#
|
170
|
+
# Example:
|
171
|
+
#
|
172
|
+
# path = Pathname.new('/usr/bin')
|
173
|
+
# path.children # => ['/usr/bin/ruby', '/usr/bin/perl', ...]
|
174
|
+
# path.children(false) # => ['ruby', 'perl', ...]
|
175
|
+
#
|
150
176
|
def children(with_directory = true)
|
151
177
|
with_directory = false if self == '.'
|
152
178
|
result = []
|
@@ -163,8 +189,12 @@ class Pathname < String
|
|
163
189
|
|
164
190
|
# Windows only
|
165
191
|
#
|
166
|
-
# Removes the decoration from a path string.
|
167
|
-
#
|
192
|
+
# Removes the decoration from a path string. Non-destructive.
|
193
|
+
#
|
194
|
+
# Example:
|
195
|
+
#
|
196
|
+
# path = Pathname.new('C:\Path\File[5].txt')
|
197
|
+
# path.undecorate # => C:\Path\File.txt.
|
168
198
|
#
|
169
199
|
def undecorate
|
170
200
|
unless @win
|
@@ -193,8 +223,12 @@ class Pathname < String
|
|
193
223
|
|
194
224
|
# Windows only
|
195
225
|
#
|
196
|
-
# Returns the short path for a long path name.
|
197
|
-
#
|
226
|
+
# Returns the short path for a long path name.
|
227
|
+
#
|
228
|
+
# Example:
|
229
|
+
#
|
230
|
+
# path = Pathname.new('C:\Program Files\Java')
|
231
|
+
# path.short_path # => C:\Progra~1\Java.
|
198
232
|
#
|
199
233
|
def short_path
|
200
234
|
unless @win
|
@@ -208,8 +242,12 @@ class Pathname < String
|
|
208
242
|
|
209
243
|
# Windows only
|
210
244
|
#
|
211
|
-
# Returns the long path for a long path name.
|
212
|
-
#
|
245
|
+
# Returns the long path for a long path name.
|
246
|
+
#
|
247
|
+
# Example:
|
248
|
+
#
|
249
|
+
# path = Pathname.new('C:\Progra~1\Java')
|
250
|
+
# path.long_path # => C:\Program Files\Java.
|
213
251
|
#
|
214
252
|
def long_path
|
215
253
|
unless @win
|
@@ -223,13 +261,18 @@ class Pathname < String
|
|
223
261
|
|
224
262
|
# Removes trailing slash, if present. Non-destructive.
|
225
263
|
#
|
264
|
+
# Example:
|
265
|
+
#
|
266
|
+
# path = Pathname.new('/usr/local/')
|
267
|
+
# path.pstrip # => '/usr/local'
|
268
|
+
#
|
226
269
|
def pstrip
|
227
270
|
str = self.dup
|
228
271
|
if @win
|
229
272
|
PathRemoveBackslash(str)
|
230
273
|
str.strip!
|
231
274
|
else
|
232
|
-
if str[-1].chr == @sep
|
275
|
+
if str.to_s[-1].chr == @sep
|
233
276
|
str.strip!
|
234
277
|
str.chop!
|
235
278
|
end
|
@@ -237,14 +280,14 @@ class Pathname < String
|
|
237
280
|
self.class.new(str)
|
238
281
|
end
|
239
282
|
|
240
|
-
#
|
283
|
+
# Performs the substitution of Pathname#pstrip in place.
|
241
284
|
#
|
242
285
|
def pstrip!
|
243
286
|
if @win
|
244
287
|
PathRemoveBackslash(self)
|
245
288
|
strip!
|
246
289
|
else
|
247
|
-
if self[-1].chr == @sep
|
290
|
+
if self.to_s[-1].chr == @sep
|
248
291
|
strip!
|
249
292
|
chop!
|
250
293
|
end
|
@@ -252,8 +295,12 @@ class Pathname < String
|
|
252
295
|
self
|
253
296
|
end
|
254
297
|
|
255
|
-
# Splits a pathname into strings based on the path separator.
|
256
|
-
#
|
298
|
+
# Splits a pathname into strings based on the path separator.
|
299
|
+
#
|
300
|
+
# Examples:
|
301
|
+
#
|
302
|
+
# Pathname.new('/usr/local/bin').to_a # => ['usr', 'local', 'bin']
|
303
|
+
# Pathname.new('C:\WINNT\Fonts').to_a # => ['C:', 'WINNT', 'Fonts']
|
257
304
|
#
|
258
305
|
def to_a
|
259
306
|
array = split(@sep) # Split string by path separator
|
@@ -263,16 +310,76 @@ class Pathname < String
|
|
263
310
|
|
264
311
|
# Yields each component of the path name to a block.
|
265
312
|
#
|
313
|
+
# Example:
|
314
|
+
#
|
315
|
+
# Pathname.new('/usr/local/bin').each{ |element|
|
316
|
+
# puts "Element: #{element}"
|
317
|
+
# }
|
318
|
+
#
|
319
|
+
# Yields 'usr', 'local', and 'bin', in turn
|
320
|
+
#
|
266
321
|
def each
|
267
322
|
to_a.each{ |element| yield element }
|
268
323
|
end
|
324
|
+
|
325
|
+
# Returns the path component at +index+, up to +length+ components, joined
|
326
|
+
# by the path separator. If the +index+ is a Range, then that is used
|
327
|
+
# instead and the +length+ is ignored.
|
328
|
+
#
|
329
|
+
# Keep in mind that on MS Windows the drive letter is the first element.
|
330
|
+
#
|
331
|
+
# Examples:
|
332
|
+
#
|
333
|
+
# path = Pathname.new('/home/john/source/ruby')
|
334
|
+
# path[0] # => 'home'
|
335
|
+
# path[1] # => 'john'
|
336
|
+
# path[0, 3] # => '/home/john/source'
|
337
|
+
# path[0..1] # => '/home/john'
|
338
|
+
#
|
339
|
+
# path = Pathname.new('C:/Documents and Settings/John/Source/Ruby')
|
340
|
+
# path[0] # => 'C:\'
|
341
|
+
# path[1] # => 'Documents and Settings'
|
342
|
+
# path[0, 3] # => 'C:\Documents and Settings\John'
|
343
|
+
# path[0..1] # => 'C:\Documents and Settings'
|
344
|
+
#
|
345
|
+
def [](index, length=nil)
|
346
|
+
if index.is_a?(Fixnum)
|
347
|
+
if length
|
348
|
+
path = File.join(to_a[index, length])
|
349
|
+
else
|
350
|
+
path = to_a[index]
|
351
|
+
end
|
352
|
+
elsif index.is_a?(Range)
|
353
|
+
if length
|
354
|
+
warn 'Length argument ignored'
|
355
|
+
end
|
356
|
+
path = File.join(to_a[index])
|
357
|
+
else
|
358
|
+
raise TypeError, "Only Fixnums and Ranges allowed as first argument"
|
359
|
+
end
|
360
|
+
|
361
|
+
if path && @win
|
362
|
+
path = path.tr("/", "\\")
|
363
|
+
end
|
364
|
+
|
365
|
+
path
|
366
|
+
end
|
269
367
|
|
270
368
|
# Yields each component of the path, concatenating the next component on
|
271
|
-
# each iteration
|
369
|
+
# each iteration as a new Pathname object, starting with the root path.
|
370
|
+
#
|
371
|
+
# Example:
|
272
372
|
#
|
273
|
-
#
|
274
|
-
#
|
275
|
-
#
|
373
|
+
# path = Pathname.new('/usr/local/bin')
|
374
|
+
#
|
375
|
+
# path.descend{ |name|
|
376
|
+
# puts name
|
377
|
+
# }
|
378
|
+
#
|
379
|
+
# First iteration => '/'
|
380
|
+
# Second iteration => '/usr'
|
381
|
+
# Third iteration => '/usr/local'
|
382
|
+
# Fourth iteration => '/usr/local/bin'
|
276
383
|
#
|
277
384
|
def descend
|
278
385
|
if root?
|
@@ -303,9 +410,18 @@ class Pathname < String
|
|
303
410
|
# Yields the path, minus one component on each iteration, as a new
|
304
411
|
# Pathname object, ending with the root path.
|
305
412
|
#
|
306
|
-
#
|
307
|
-
#
|
308
|
-
#
|
413
|
+
# Example:
|
414
|
+
#
|
415
|
+
# path = Pathname.new('/usr/local/bin')
|
416
|
+
#
|
417
|
+
# path.ascend{ |name|
|
418
|
+
# puts name
|
419
|
+
# }
|
420
|
+
#
|
421
|
+
# First iteration => '/usr/local/bin'
|
422
|
+
# Second iteration => '/usr/local'
|
423
|
+
# Third iteration => '/usr'
|
424
|
+
# Fourth iteration => '/'
|
309
425
|
#
|
310
426
|
def ascend
|
311
427
|
if root?
|
@@ -349,6 +465,16 @@ class Pathname < String
|
|
349
465
|
# to the drive letter, or the server and share path if the path is a
|
350
466
|
# UNC path.
|
351
467
|
#
|
468
|
+
# Examples:
|
469
|
+
#
|
470
|
+
# Pathname.new('/usr/local').root # => '/'
|
471
|
+
# Pathname.new('lib') # => '.'
|
472
|
+
#
|
473
|
+
# On MS Windows:
|
474
|
+
#
|
475
|
+
# Pathname.new('C:\WINNT').root # => 'C:'
|
476
|
+
# Pathname.new('\\some\share\foo').root # => '\\some\share'
|
477
|
+
#
|
352
478
|
def root
|
353
479
|
dir = "."
|
354
480
|
if @win
|
@@ -366,6 +492,11 @@ class Pathname < String
|
|
366
492
|
|
367
493
|
# Returns whether or not the path consists only of a root directory.
|
368
494
|
#
|
495
|
+
# Examples:
|
496
|
+
#
|
497
|
+
# Pathname.new('/').root? # => true
|
498
|
+
# Pathname.new('/foo').root? # => false
|
499
|
+
#
|
369
500
|
def root?
|
370
501
|
if @win
|
371
502
|
PathIsRoot(self)
|
@@ -374,11 +505,16 @@ class Pathname < String
|
|
374
505
|
end
|
375
506
|
end
|
376
507
|
|
377
|
-
# Windows only
|
508
|
+
# MS Windows only
|
378
509
|
#
|
379
510
|
# Determines if the string is a valid Universal Naming Convention (UNC)
|
380
511
|
# for a server and share path.
|
381
512
|
#
|
513
|
+
# Examples:
|
514
|
+
#
|
515
|
+
# Pathname.new("\\\\foo\\bar").unc? # => true
|
516
|
+
# Pathname.new('C:\Program Files').unc? # => false
|
517
|
+
#
|
382
518
|
def unc?
|
383
519
|
unless @win
|
384
520
|
raise NotImplementedError, "not supported on this platform"
|
@@ -387,12 +523,14 @@ class Pathname < String
|
|
387
523
|
PathIsUNC(self)
|
388
524
|
end
|
389
525
|
|
390
|
-
# Windows only
|
526
|
+
# MS Windows only
|
391
527
|
#
|
392
528
|
# Returns the drive number that corresponds to the root, or nil if not
|
393
529
|
# applicable.
|
394
530
|
#
|
395
|
-
#
|
531
|
+
# Example:
|
532
|
+
#
|
533
|
+
# Pathname.new("C:\\foo").drive_number # => 2
|
396
534
|
#
|
397
535
|
def drive_number
|
398
536
|
unless @win
|
@@ -406,6 +544,15 @@ class Pathname < String
|
|
406
544
|
# Compares two Pathname objects. Note that Pathnames may only be compared
|
407
545
|
# against other Pathnames, not strings. Otherwise nil is returned.
|
408
546
|
#
|
547
|
+
# Example:
|
548
|
+
#
|
549
|
+
# path1 = Pathname.new('/usr/local')
|
550
|
+
# path2 = Pathname.new('/usr/local')
|
551
|
+
# path3 = Pathname.new('/usr/local/bin')
|
552
|
+
#
|
553
|
+
# path1 <=> path2 # => 0
|
554
|
+
# path1 <=> path3 # => -1
|
555
|
+
#
|
409
556
|
def <=>(string)
|
410
557
|
return nil unless string.kind_of?(Pathname)
|
411
558
|
super
|
@@ -413,20 +560,33 @@ class Pathname < String
|
|
413
560
|
|
414
561
|
# Returns the parent directory of the given path.
|
415
562
|
#
|
563
|
+
# Example:
|
564
|
+
#
|
565
|
+
# Pathname.new('/usr/local/bin').parent # => '/usr/local'
|
566
|
+
#
|
416
567
|
def parent
|
417
568
|
self + ".."
|
418
569
|
end
|
419
570
|
|
420
571
|
# Returns a relative path from the argument to the receiver. If +self+
|
421
572
|
# is absolute, the argument must be absolute too. If +self+ is relative,
|
422
|
-
# the argument must be relative too.
|
573
|
+
# the argument must be relative too. For relative paths, this method
|
574
|
+
# an imaginary, common parent path.
|
423
575
|
#
|
424
576
|
# This method does not access the filesystem. It assumes no symlinks.
|
425
577
|
# You should only compare directories against directories, or files against
|
426
|
-
# files, or you may
|
578
|
+
# files, or you may get unexpected results.
|
427
579
|
#
|
428
580
|
# Raises an ArgumentError if it cannot find a relative path.
|
429
581
|
#
|
582
|
+
# Examples:
|
583
|
+
#
|
584
|
+
# path = Pathname.new('/usr/local/bin')
|
585
|
+
# path.relative_path_from('/usr/bin') # => "../local/bin"
|
586
|
+
#
|
587
|
+
# path = Pathname.new("C:\\WINNT\\Fonts")
|
588
|
+
# path.relative_path_from("C:\\Program Files") # => "..\\WINNT\\Fonts"
|
589
|
+
#
|
430
590
|
def relative_path_from(base)
|
431
591
|
base = self.class.new(base) unless base.kind_of?(Pathname)
|
432
592
|
|
@@ -478,14 +638,15 @@ class Pathname < String
|
|
478
638
|
# Adds two Pathname objects together, or a Pathname and a String. It
|
479
639
|
# also automatically cleans the Pathname.
|
480
640
|
#
|
641
|
+
# Adding a root path to an existing path merely replaces the current
|
642
|
+
# path. Adding '.' to an existing path does nothing.
|
643
|
+
#
|
481
644
|
# Example:
|
645
|
+
#
|
482
646
|
# path1 = '/foo/bar'
|
483
647
|
# path2 = '../baz'
|
484
648
|
# path1 + path2 # '/foo/baz'
|
485
649
|
#
|
486
|
-
# Adding a root path to an existing path merely replaces the current
|
487
|
-
# path. Adding '.' to an existing path does nothing.
|
488
|
-
#
|
489
650
|
def +(string)
|
490
651
|
unless string.kind_of?(Pathname)
|
491
652
|
string = self.class.new(string)
|
@@ -517,16 +678,27 @@ class Pathname < String
|
|
517
678
|
|
518
679
|
self.class.new(new_string).clean
|
519
680
|
end
|
681
|
+
|
520
682
|
alias :/ :+
|
521
683
|
|
522
684
|
# Returns whether or not the path is an absolute path.
|
523
685
|
#
|
686
|
+
# Example:
|
687
|
+
#
|
688
|
+
# Pathname.new('/usr/bin').absolute? # => true
|
689
|
+
# Pathname.new('usr').absolute? # => false
|
690
|
+
#
|
524
691
|
def absolute?
|
525
692
|
!relative?
|
526
693
|
end
|
527
694
|
|
528
695
|
# Returns whether or not the path is a relative path.
|
529
696
|
#
|
697
|
+
# Example:
|
698
|
+
#
|
699
|
+
# Pathname.new('/usr/bin').relative? # => true
|
700
|
+
# Pathname.new('usr').relative? # => false
|
701
|
+
#
|
530
702
|
def relative?
|
531
703
|
if @win
|
532
704
|
PathIsRelative(self)
|
@@ -536,7 +708,12 @@ class Pathname < String
|
|
536
708
|
end
|
537
709
|
|
538
710
|
# Removes unnecessary '.' paths and ellides '..' paths appropriately.
|
539
|
-
#
|
711
|
+
# This method is non-destructive.
|
712
|
+
#
|
713
|
+
# Example:
|
714
|
+
#
|
715
|
+
# path = Pathname.new('/usr/./local/../bin')
|
716
|
+
# path.clean # => '/usr/bin'
|
540
717
|
#
|
541
718
|
def clean
|
542
719
|
return self if self.empty?
|
@@ -551,6 +728,7 @@ class Pathname < String
|
|
551
728
|
end
|
552
729
|
|
553
730
|
final = []
|
731
|
+
|
554
732
|
to_a.each{ |element|
|
555
733
|
next if element == "."
|
556
734
|
final.push(element)
|
@@ -558,15 +736,18 @@ class Pathname < String
|
|
558
736
|
2.times{ final.pop }
|
559
737
|
end
|
560
738
|
}
|
739
|
+
|
561
740
|
final = final.join(@sep)
|
562
741
|
final = root._plus_(final) if root != "."
|
563
742
|
final = "." if final.empty?
|
743
|
+
|
564
744
|
self.class.new(final)
|
565
745
|
end
|
746
|
+
|
566
747
|
alias :cleanpath :clean
|
567
748
|
|
568
|
-
#
|
569
|
-
#
|
749
|
+
# Identical to Pathname#clean, except that it modifies the receiver
|
750
|
+
# in place.
|
570
751
|
#
|
571
752
|
def clean!
|
572
753
|
return self if self.empty?
|
@@ -580,6 +761,7 @@ class Pathname < String
|
|
580
761
|
end
|
581
762
|
|
582
763
|
final = []
|
764
|
+
|
583
765
|
to_a.each{ |element|
|
584
766
|
next if element == "."
|
585
767
|
final.push(element)
|
@@ -587,13 +769,17 @@ class Pathname < String
|
|
587
769
|
2.times{ final.pop }
|
588
770
|
end
|
589
771
|
}
|
772
|
+
|
590
773
|
final = final.join(@sep)
|
591
774
|
final = root + final if root != "."
|
592
775
|
final = "." if final.empty?
|
593
776
|
replace(self.class.new(final))
|
777
|
+
|
594
778
|
self
|
595
779
|
end
|
596
780
|
|
781
|
+
alias cleanpath! clean!
|
782
|
+
|
597
783
|
#-- Find facade
|
598
784
|
|
599
785
|
# Pathname#find is an iterator to traverse a directory tree in a depth first
|
@@ -874,7 +1060,3 @@ module Kernel
|
|
874
1060
|
instance_eval{ Pathname.new(yield) }
|
875
1061
|
end
|
876
1062
|
end
|
877
|
-
|
878
|
-
if $0 == __FILE__
|
879
|
-
path = Pathname.new(Dir.pwd)
|
880
|
-
end
|
data/test/test_pathname.rb
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
##############################################################################
|
8
8
|
require 'pathname2'
|
9
9
|
require 'test/unit'
|
10
|
+
require 'rbconfig'
|
11
|
+
include Config
|
10
12
|
|
11
13
|
class MyPathname < Pathname; end
|
12
14
|
|
@@ -63,7 +65,7 @@ class TC_Pathname < Test::Unit::TestCase
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def test_version
|
66
|
-
assert_equal('1.6.
|
68
|
+
assert_equal('1.6.1', Pathname::VERSION)
|
67
69
|
end
|
68
70
|
|
69
71
|
def test_file_url_path
|
@@ -75,7 +77,7 @@ class TC_Pathname < Test::Unit::TestCase
|
|
75
77
|
assert_equal(@pwd, Pathname.new('.').realpath)
|
76
78
|
assert_kind_of(Pathname, Pathname.new('/dev/stdin').realpath)
|
77
79
|
assert(Pathname.new('/dev/stdin') != Pathname.new('/dev/stdin').realpath)
|
78
|
-
if
|
80
|
+
if CONFIG['host_os'] =~ /bsd|darwin|mac/i
|
79
81
|
assert_raises(Errno::ENOENT){ Pathname.new('../blahblah/bogus').realpath }
|
80
82
|
else
|
81
83
|
assert_raises(Errno::ENOENT){ Pathname.new('../bogus').realpath }
|
@@ -83,7 +85,7 @@ class TC_Pathname < Test::Unit::TestCase
|
|
83
85
|
end
|
84
86
|
|
85
87
|
def test_realpath_platform
|
86
|
-
case
|
88
|
+
case CONFIG['host_os']
|
87
89
|
when /linux/i
|
88
90
|
path1 = '/dev/stdin'
|
89
91
|
assert_equal('/dev/pts/0', Pathname.new(path1).realpath)
|
@@ -229,7 +231,6 @@ class TC_Pathname < Test::Unit::TestCase
|
|
229
231
|
Dir.pwd + '/Rakefile',
|
230
232
|
Dir.pwd + '/examples',
|
231
233
|
Dir.pwd + '/ext',
|
232
|
-
Dir.pwd + '/install.rb',
|
233
234
|
Dir.pwd + '/lib',
|
234
235
|
Dir.pwd + '/pathname2.gemspec',
|
235
236
|
Dir.pwd + '/test'
|
@@ -246,7 +247,7 @@ class TC_Pathname < Test::Unit::TestCase
|
|
246
247
|
assert_equal(
|
247
248
|
[
|
248
249
|
'CHANGES', 'MANIFEST', 'README', 'Rakefile', 'examples', 'ext',
|
249
|
-
'
|
250
|
+
'lib', 'pathname2.gemspec', 'test'
|
250
251
|
],
|
251
252
|
children.sort
|
252
253
|
)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
##########################################################################
|
2
|
-
#
|
2
|
+
# test_pathname_win.rb
|
3
3
|
#
|
4
4
|
# MS Windows test suite for the Pathname class. To test explicitly
|
5
5
|
# against the C extension pass the letter 'c' as an argument. You should
|
@@ -39,8 +39,28 @@ class TC_Pathname_MSWin < Test::Unit::TestCase
|
|
39
39
|
@unc_array = []
|
40
40
|
end
|
41
41
|
|
42
|
+
def test_aref_with_range
|
43
|
+
assert_equal("C:\\Program Files", @fpath[0..1])
|
44
|
+
assert_equal("C:\\Program Files\\Windows NT", @fpath[0..2])
|
45
|
+
assert_equal("Program Files\\Windows NT", @fpath[1..2])
|
46
|
+
assert_equal(@fpath, @fpath[0..-1])
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_aref_with_index_and_length
|
50
|
+
assert_equal("C:", @fpath[0,1])
|
51
|
+
assert_equal("C:\\Program Files", @fpath[0,2])
|
52
|
+
assert_equal("Program Files\\Windows NT", @fpath[1,2])
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_aref_with_index
|
56
|
+
assert_equal("C:", @fpath[0])
|
57
|
+
assert_equal("Program Files", @fpath[1])
|
58
|
+
assert_equal("Accessories", @fpath[-1])
|
59
|
+
assert_equal(nil, @fpath[10])
|
60
|
+
end
|
61
|
+
|
42
62
|
def test_version
|
43
|
-
assert_equal("1.6.
|
63
|
+
assert_equal("1.6.1", Pathname::VERSION)
|
44
64
|
end
|
45
65
|
|
46
66
|
# Convenience method for test_plus
|
@@ -596,8 +616,8 @@ class TC_Pathname_MSWin < Test::Unit::TestCase
|
|
596
616
|
|
597
617
|
assert_equal(
|
598
618
|
[
|
599
|
-
"CHANGES","examples","ext","
|
600
|
-
"
|
619
|
+
"CHANGES", "examples", "ext", "lib", "MANIFEST",
|
620
|
+
"pathname2.gemspec", "Rakefile", "README", "test"
|
601
621
|
],
|
602
622
|
children
|
603
623
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathname2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -36,12 +36,10 @@ files:
|
|
36
36
|
- lib/pathname2.rb
|
37
37
|
- CHANGES
|
38
38
|
- MANIFEST
|
39
|
-
- README
|
40
39
|
- Rakefile
|
41
|
-
-
|
40
|
+
- README
|
42
41
|
- test/test_pathname.rb
|
43
42
|
- test/test_pathname_windows.rb
|
44
|
-
- test/CVS
|
45
43
|
has_rdoc: true
|
46
44
|
homepage: http://www.rubyforge.org/projects/shards
|
47
45
|
post_install_message:
|