pathname2 1.6.4-x86-mingw32
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/CHANGES +129 -0
- data/MANIFEST +11 -0
- data/README +99 -0
- data/Rakefile +43 -0
- data/benchmarks/bench_pathname.rb +127 -0
- data/benchmarks/bench_plus.rb +34 -0
- data/examples/example_pathname.rb +25 -0
- data/lib/pathname2.rb +1124 -0
- data/pathname2.gemspec +37 -0
- data/test/test_pathname.rb +480 -0
- data/test/test_pathname_windows.rb +678 -0
- metadata +126 -0
data/CHANGES
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
== 1.6.4 - 20-Jan-2011
|
2
|
+
* Explicitly remove the Pathname const if it is already defined in order
|
3
|
+
to avoid a superclass mismatch error. This library assumes that if you
|
4
|
+
require pathname2, you want my version of the Pathname class.
|
5
|
+
* Updated URI handling for Ruby 1.9.x.
|
6
|
+
* Added the Pathname() method, a synonym for Pathname.new.
|
7
|
+
* Some Rakefile and gemspec tweaks.
|
8
|
+
* Some updates to the test suite, including some specifically for Windows 7.
|
9
|
+
|
10
|
+
== 1.6.3 - 2-Oct-2009
|
11
|
+
* Updated Windows platform handling code to include mingw and cygwin.
|
12
|
+
* Added the :gem rake task.
|
13
|
+
* Minor gemspec updates.
|
14
|
+
* Some minor test suite updates.
|
15
|
+
|
16
|
+
== 1.6.2 - 4-Aug-2009
|
17
|
+
* Now compatible with Ruby 1.9.x.
|
18
|
+
* License changed to Artistic 2.0.
|
19
|
+
* Added the Pathname.pwd method as a synonym for Pathname.new(Dir.pwd).
|
20
|
+
* Modified Pathname#dirname so that you can specify a level that indicates
|
21
|
+
how many levels up you want to retrieve. For example, if your path was
|
22
|
+
'/usr/local/bin', then path.dirname(2) would return '/usr'.
|
23
|
+
* Now compatible with Ruby 1.9.x.
|
24
|
+
* Bumped required version of the facade library to 1.0.4.
|
25
|
+
|
26
|
+
== 1.6.1 - 8-Nov-2008
|
27
|
+
* Added the Pathname#[] method, which accepts an index, an index plus a
|
28
|
+
length, or a range, and returns appropriate the path element(s).
|
29
|
+
* Refactoring the platform checking in the test suite to use rbconfig instead
|
30
|
+
of RUBY_PLATFORM.
|
31
|
+
* More inline documentation examples.
|
32
|
+
|
33
|
+
== 1.6.0 - 13-July-2008
|
34
|
+
* The facade for ftools (and ftools itself) has been removed. The ftools
|
35
|
+
library is deprecated in favor of FileUtils.
|
36
|
+
* PathnameError is now Pathname::Error.
|
37
|
+
* Bug fix for Pathname#relative_path_from for MS Windows. Thanks go to an
|
38
|
+
anonymous user for the spot.
|
39
|
+
* Fixed a bug where frozen strings would raise an error on MS Windows.
|
40
|
+
* The code is now -w clean.
|
41
|
+
* Removed the C version as part of the release because it was just too
|
42
|
+
difficult to maintain both versions. The C code remains in CVS, however.
|
43
|
+
* Changed platform checking to use rbconfig instead of RUBY_PLATFORM to avoid
|
44
|
+
potential issues with other Ruby implementation.
|
45
|
+
|
46
|
+
== 1.5.2 - 9-Mar-2007
|
47
|
+
* Bug fix for the Pathname#realpath method where it was not handling recursive
|
48
|
+
symlinks. The C version was also fixed, but it only affected platforms that
|
49
|
+
don't have the realpath() function.
|
50
|
+
* Added a test for recursive symlinks (for Solaris, anyway).
|
51
|
+
* Updated the docs for Pathname#realpath.
|
52
|
+
* Minor speed enhancements for the C version and the elimination of one
|
53
|
+
(potential) segfault.
|
54
|
+
* Added a 'Future Plans' section to the README.
|
55
|
+
* Added a Rakefile. You can now build, clean, and test and install (both the
|
56
|
+
pure Ruby and C versions).
|
57
|
+
|
58
|
+
== 1.5.1 - 28-Aug-2006
|
59
|
+
* Added the Kernel#pn method as a shortcut for Pathname.new.
|
60
|
+
* The Pathname#readlink now properly handles symbolic links. The 'fix'
|
61
|
+
from 1.4.4 did not work.
|
62
|
+
* The C extension uses your system's realpath() function for the
|
63
|
+
Pathname#readlink method if it has one.
|
64
|
+
* Added the '/' alias for '+'. So, p1 / p2 is the same as p1 + p2.
|
65
|
+
* The windows-pr package is now required on MS Windows.
|
66
|
+
|
67
|
+
== 1.5.0 - 17-Apr-2006
|
68
|
+
* Better subclass handling, in that some methods that previously returned
|
69
|
+
hardcoded Pathname.new now return self.class.new.
|
70
|
+
* File URL's are now handled on Unix as well (using the 'uri' package).
|
71
|
+
* Some comment changes/clarifications.
|
72
|
+
* Added the PathnameError class to the pure Ruby version.
|
73
|
+
|
74
|
+
== 1.4.4 - 23-Mar-2006
|
75
|
+
* If the path is a symbolic link the Pathname#realpath method
|
76
|
+
now returns the absolute path of that link, i.e. the result
|
77
|
+
of File.readlink (as a Pathname object).
|
78
|
+
|
79
|
+
== 1.4.3 - 3-Mar-2006
|
80
|
+
* Added the Pathname#realpath method.
|
81
|
+
|
82
|
+
== 1.4.2 - 22-Feb-2006
|
83
|
+
* Fixed the Pathname#relative_path_from method for Windows. This really only
|
84
|
+
affected edge cases that you probably never saw anyway.
|
85
|
+
* Added corresponding tests for Windows.
|
86
|
+
|
87
|
+
== 1.4.1 - 18-Feb-2006
|
88
|
+
* Added the Pathname#parent method.
|
89
|
+
* Added the Pathname#relative_path_from method.
|
90
|
+
* Bug fix for Pathname#pstrip on *nix.
|
91
|
+
* Corresponding test suite additions.
|
92
|
+
|
93
|
+
== 1.4.0 - 19-Dec-2005
|
94
|
+
* Added destructive and non-destructive methods for some methods - pstrip,
|
95
|
+
pstrip!, undecorate, undecorate!, clean and clean!.
|
96
|
+
* Added a C extension version of this package. You can use the C version
|
97
|
+
instead of the pure Ruby version instead. See the README for more details.
|
98
|
+
* Fixed bug in the root method where the result wasn't guaranteed to be a
|
99
|
+
Pathname class.
|
100
|
+
* Fixed bugs in Windows version where the receiver was inadvertantly modified
|
101
|
+
in some cases, and added tests to check for this in the future.
|
102
|
+
* Modified the Dir.glob facade so that it (temporarily) changes to the path
|
103
|
+
directory, globs on that path, then returns to the original directory.
|
104
|
+
* Added the bench_pathname.rb script to let you benchmark all Pathname
|
105
|
+
methods.
|
106
|
+
|
107
|
+
== 1.3.1 - 21-Nov-2005
|
108
|
+
* Added the Pathname#children method.
|
109
|
+
* Added tests for the Pathname#children method.
|
110
|
+
|
111
|
+
== 1.3.0 - 28-Oct-2005
|
112
|
+
* Added the short_path and long_path methods for MS Windows.
|
113
|
+
* Optimization for the '+' method on Unix.
|
114
|
+
* Added some examples under the 'examples' directory.
|
115
|
+
* More tests added and some minor changes to the test suite in general.
|
116
|
+
|
117
|
+
== 1.2.1 - 1-Sep-2005
|
118
|
+
* Bug fix for the ascend and descend methods wrt Windows and UNC paths.
|
119
|
+
* More tests added for ascend and descend methods.
|
120
|
+
|
121
|
+
== 1.2.0 - 29-Aug-2005
|
122
|
+
* Added the 'ascend' and 'descend' methods.
|
123
|
+
* Added corresponding test suite additions.
|
124
|
+
|
125
|
+
== 1.1.0 - 13-Jul-2005
|
126
|
+
* Added the 'find' facade.
|
127
|
+
|
128
|
+
== 1.0.0 - 11-Jun-2005
|
129
|
+
* Initial release
|
data/MANIFEST
ADDED
data/README
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
== Description
|
2
|
+
A drop-in replacement for the current Pathname class.
|
3
|
+
|
4
|
+
== Prerequisites
|
5
|
+
* facade 1.0.4 or later
|
6
|
+
* windows-pr 1.1.2 or later (Windows only)
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
gem install pathname2
|
11
|
+
|
12
|
+
== Synopsis
|
13
|
+
require 'pathname2'
|
14
|
+
|
15
|
+
# Unix
|
16
|
+
path1 = "/foo/bar/baz"
|
17
|
+
path2 = "../zap"
|
18
|
+
|
19
|
+
path1 + path2 # "/foo/bar/zap"
|
20
|
+
path1 / path2 # "/foo/bar/zap" (same as +)
|
21
|
+
path1.exists? # Does this path exist?
|
22
|
+
path1.dirname # "/foo/bar"
|
23
|
+
path1.to_a # ['foo','bar','baz']
|
24
|
+
|
25
|
+
# Windows
|
26
|
+
path1 = "C:/foo/bar/baz"
|
27
|
+
path2 = "../zap"
|
28
|
+
|
29
|
+
path1 + path2 # "C:\\foo\\bar\\zap"
|
30
|
+
path1.root # "C:\\"
|
31
|
+
path1.to_a # ['C:','foo','bar','baz']
|
32
|
+
|
33
|
+
== Windows Notes
|
34
|
+
All forward slashes are converted to backslashes for Pathname objects.
|
35
|
+
|
36
|
+
== Differences between Unix and Windows
|
37
|
+
If your pathname consists solely of ".", or "..", the return
|
38
|
+
value for Pathname#clean will be different. On Win32, "\\" is returned,
|
39
|
+
while on Unix "." is returned. I consider this an extreme edge case and
|
40
|
+
will not worry myself with it.
|
41
|
+
|
42
|
+
== Differences between Pathname in the standard library and this version
|
43
|
+
* It is a subclass of String (and thus, mixes in Enumerable).
|
44
|
+
* It has sensical to_a and root instance methods.
|
45
|
+
* It works on Windows and Unix. The current implementation does not work
|
46
|
+
with Windows path names very well, and not at all when it comes to UNC
|
47
|
+
paths.
|
48
|
+
* The Pathname#cleanpath method works differently - it always returns
|
49
|
+
a canonical pathname. In addition, there is no special consideration
|
50
|
+
for symlinks (yet), though I'm not sure it warrants it.
|
51
|
+
* The Pathname#+ method auto cleans.
|
52
|
+
* It uses a facade for all File and Dir methods, as well as most FileUtils
|
53
|
+
methods.
|
54
|
+
* Pathname#clean works slightly differently. In the stdlib version,
|
55
|
+
Pathname#clean("../a") returns "../a". In this version, it returns "a".
|
56
|
+
This affects other methods, such as Pathname#relative_path_from.
|
57
|
+
* Accepts file urls and converts them to paths automatically, e.g.
|
58
|
+
file:///foo%20bar/baz becomes '/foo/bar/baz'.
|
59
|
+
* Adds a Kernel level +pn+ method as a shortcut.
|
60
|
+
* Allows you to add paths together with the '/' operator.
|
61
|
+
|
62
|
+
== Method Priority
|
63
|
+
Because there is some overlap in method names between File, Dir, and
|
64
|
+
FileUtils, the priority is as follows:
|
65
|
+
|
66
|
+
* File
|
67
|
+
* Dir
|
68
|
+
* FileUtils
|
69
|
+
|
70
|
+
In other words, whichever of these defines a given method first is the
|
71
|
+
method that is used by the pathname2 library.
|
72
|
+
|
73
|
+
== Known Issues
|
74
|
+
In Ruby 1.8.3 and 1.8.4 you will see a failure in the test suite regarding
|
75
|
+
'fu_world_writable?' from FileUtils. You can ignore this. That method is
|
76
|
+
supposed to be private. See ruby-core:7383.
|
77
|
+
|
78
|
+
Any other issues should be reported on the project page at
|
79
|
+
http://www.rubyforge.org/projects/shards
|
80
|
+
|
81
|
+
The git repo itself is located at https://github.com/djberg96/pathname2
|
82
|
+
|
83
|
+
== Future Plans
|
84
|
+
Suggestions welcome.
|
85
|
+
|
86
|
+
== License
|
87
|
+
Artistic 2.0
|
88
|
+
|
89
|
+
== Copyright
|
90
|
+
(C) 2003-2011 Daniel J. Berger
|
91
|
+
All rights reserved.
|
92
|
+
|
93
|
+
== Warranty
|
94
|
+
This library is provided "as is" and without any express or
|
95
|
+
implied warranties, including, without limitation, the implied
|
96
|
+
warranties of merchantability and fitness for a particular purpose.
|
97
|
+
|
98
|
+
== Author
|
99
|
+
Daniel J. Berger
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
CLEAN.include("**/*.gem", "**/*.rbc")
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
desc "Build the pathname2 gem"
|
9
|
+
task :create => [:clean] do
|
10
|
+
spec = eval(IO.read('pathname2.gemspec'))
|
11
|
+
Gem::Builder.new(spec).build
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Install the pathname2 gem"
|
15
|
+
task :install => [:create] do
|
16
|
+
file = Dir["*.gem"].first
|
17
|
+
sh "gem install #{file}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Run the test suite for the pure Ruby version'
|
22
|
+
Rake::TestTask.new('test') do |t|
|
23
|
+
t.warning = true
|
24
|
+
t.verbose = true
|
25
|
+
|
26
|
+
if Config::CONFIG['host_os'] =~ /mswin|win32|dos|cygwin|mingw/i
|
27
|
+
t.test_files = FileList['test/test_pathname_windows.rb']
|
28
|
+
else
|
29
|
+
t.test_files = FileList['test/test_pathname.rb']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Run the Pathname benchmark suite'
|
34
|
+
task :benchmark do
|
35
|
+
sh 'ruby -Ilib benchmarks/bench_pathname.rb'
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Run the benchmark suite for Pathname#+ vs File.join'
|
39
|
+
task :benchmark_plus do
|
40
|
+
sh 'ruby -Ilib benchmarks/bench_plus.rb'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# bench_pathname.rb
|
3
|
+
#
|
4
|
+
# Benchmark suite for all methods of the Pathname class, excluding
|
5
|
+
# the facade methods.
|
6
|
+
#
|
7
|
+
# Use the Rake tasks to run this benchmark:
|
8
|
+
#
|
9
|
+
# => rake benchmark to run the pure Ruby benchmark.
|
10
|
+
#####################################################################
|
11
|
+
require 'benchmark'
|
12
|
+
require 'pathname2'
|
13
|
+
require 'rbconfig'
|
14
|
+
|
15
|
+
if Config::CONFIG['host_os'].match("mswin")
|
16
|
+
path1 = Pathname.new("C:\\Program Files\\Windows NT")
|
17
|
+
path2 = Pathname.new("Accessories")
|
18
|
+
path3 = Pathname.new("C:\\Program Files\\..\\.\\Windows NT")
|
19
|
+
else
|
20
|
+
path1 = Pathname.new("/usr/local")
|
21
|
+
path2 = Pathname.new("bin")
|
22
|
+
path3 = Pathname.new("/usr/../local/./bin")
|
23
|
+
path4 = Pathname.new("/dev/stdin")
|
24
|
+
end
|
25
|
+
|
26
|
+
MAX = 10000
|
27
|
+
|
28
|
+
Benchmark.bm(25) do |bench|
|
29
|
+
bench.report("Pathname.new(path)"){
|
30
|
+
MAX.times{ Pathname.new("/usr/local/bin") }
|
31
|
+
}
|
32
|
+
|
33
|
+
bench.report("Pathname#+(Pathname)"){
|
34
|
+
MAX.times{ path1 + path2 }
|
35
|
+
}
|
36
|
+
|
37
|
+
bench.report("Pathname#+(String)"){
|
38
|
+
MAX.times{ path1 + path2 }
|
39
|
+
}
|
40
|
+
|
41
|
+
bench.report("Pathname#children"){
|
42
|
+
MAX.times{ path1.children }
|
43
|
+
}
|
44
|
+
|
45
|
+
bench.report("Pathname#pstrip"){
|
46
|
+
MAX.times{ path1.pstrip }
|
47
|
+
}
|
48
|
+
|
49
|
+
bench.report("Pathname#pstrip!"){
|
50
|
+
MAX.times{ path1.pstrip! }
|
51
|
+
}
|
52
|
+
|
53
|
+
bench.report("Pathname#to_a"){
|
54
|
+
MAX.times{ path1.to_a }
|
55
|
+
}
|
56
|
+
|
57
|
+
bench.report("Pathname#descend"){
|
58
|
+
MAX.times{ path1.descend{} }
|
59
|
+
}
|
60
|
+
|
61
|
+
bench.report("Pathname#ascend"){
|
62
|
+
MAX.times{ path1.ascend{} }
|
63
|
+
}
|
64
|
+
|
65
|
+
bench.report("Pathname#root"){
|
66
|
+
MAX.times{ path1.root }
|
67
|
+
}
|
68
|
+
|
69
|
+
bench.report("Pathname#root?"){
|
70
|
+
MAX.times{ path1.root? }
|
71
|
+
}
|
72
|
+
|
73
|
+
bench.report("Pathname#<=>"){
|
74
|
+
MAX.times{ path1 <=> path2 }
|
75
|
+
}
|
76
|
+
|
77
|
+
bench.report("Pathname#absolute?"){
|
78
|
+
MAX.times{ path1.absolute? }
|
79
|
+
}
|
80
|
+
|
81
|
+
bench.report("Pathname#relative?"){
|
82
|
+
MAX.times{ path1.relative? }
|
83
|
+
}
|
84
|
+
|
85
|
+
bench.report("Pathname#clean"){
|
86
|
+
MAX.times{ path3.clean }
|
87
|
+
}
|
88
|
+
|
89
|
+
bench.report("Pathname#clean!"){
|
90
|
+
MAX.times{ path3.clean! }
|
91
|
+
}
|
92
|
+
|
93
|
+
# Platform specific tests
|
94
|
+
if Config::CONFIG['host_os'].match("mswin")
|
95
|
+
bench.report("Pathname.new(file_url)"){
|
96
|
+
MAX.times{ Pathname.new("file:///C:/usr/local/bin") }
|
97
|
+
}
|
98
|
+
|
99
|
+
bench.report("Pathname#drive_number"){
|
100
|
+
MAX.times{ path1.drive_number }
|
101
|
+
}
|
102
|
+
|
103
|
+
bench.report("Pathname#unc?"){
|
104
|
+
MAX.times{ path1.unc? }
|
105
|
+
}
|
106
|
+
|
107
|
+
bench.report("Pathname#undecorate"){
|
108
|
+
MAX.times{ path1.undecorate }
|
109
|
+
}
|
110
|
+
|
111
|
+
bench.report("Pathname#undecorate!"){
|
112
|
+
MAX.times{ path1.undecorate! }
|
113
|
+
}
|
114
|
+
|
115
|
+
bench.report("Pathname#short_path"){
|
116
|
+
MAX.times{ path1.short_path }
|
117
|
+
}
|
118
|
+
|
119
|
+
bench.report("Pathname#long_path"){
|
120
|
+
MAX.times{ path1.long_path }
|
121
|
+
}
|
122
|
+
else
|
123
|
+
bench.report("Pathname#realpath"){
|
124
|
+
MAX.times{ path4.realpath }
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# Compare File.join vs. Pathname#+
|
3
|
+
#
|
4
|
+
# This benchmark was inspired by a post by Thomas Sawyer. Note that
|
5
|
+
# Pathname#+ will never be as fast as File.join, but this provides a
|
6
|
+
# good base for further optimizations.
|
7
|
+
#
|
8
|
+
# Also keep in mind that File.join does no path normalization whatsoever,
|
9
|
+
# e.g. File.join("foo", "/bar") behaves differently than Pathname.new("foo")
|
10
|
+
# + Pathname.new("/bar"). This is true of both the pathname and pathname2
|
11
|
+
# packages.
|
12
|
+
#
|
13
|
+
# You can run this via the 'rake benchmark_plus' task.
|
14
|
+
##############################################################################
|
15
|
+
require 'benchmark'
|
16
|
+
require 'pathname2'
|
17
|
+
|
18
|
+
MAX = 10000
|
19
|
+
|
20
|
+
s1 = "a/b/c"
|
21
|
+
s2 = "d/e/f"
|
22
|
+
|
23
|
+
path1 = Pathname.new(s1)
|
24
|
+
path2 = Pathname.new(s2)
|
25
|
+
|
26
|
+
Benchmark.bm(10) do |bench|
|
27
|
+
bench.report("File.join"){
|
28
|
+
MAX.times{ File.join(s1, s2) }
|
29
|
+
}
|
30
|
+
|
31
|
+
bench.report("Pathname#+"){
|
32
|
+
MAX.times{ path1 + path2 }
|
33
|
+
}
|
34
|
+
end
|