pathname2 1.6.5-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +135 -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 +1131 -0
- data/pathname2.gemspec +39 -0
- data/test/test_pathname.rb +487 -0
- data/test/test_pathname_windows.rb +678 -0
- metadata +118 -0
data/CHANGES
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
== 1.6.5 - 19-Sep-2011
|
2
|
+
* Added the String#to_path instance method. This returns a Pathname
|
3
|
+
object.
|
4
|
+
* The architecture for the Windows gem is now "universal", and some
|
5
|
+
gemspec dependencies were simplified.
|
6
|
+
|
7
|
+
== 1.6.4 - 20-Jan-2011
|
8
|
+
* Explicitly remove the Pathname const if it is already defined in order
|
9
|
+
to avoid a superclass mismatch error. This library assumes that if you
|
10
|
+
require pathname2, you want my version of the Pathname class.
|
11
|
+
* Updated URI handling for Ruby 1.9.x.
|
12
|
+
* Added the Pathname() method, a synonym for Pathname.new.
|
13
|
+
* Some Rakefile and gemspec tweaks.
|
14
|
+
* Some updates to the test suite, including some specifically for Windows 7.
|
15
|
+
|
16
|
+
== 1.6.3 - 2-Oct-2009
|
17
|
+
* Updated Windows platform handling code to include mingw and cygwin.
|
18
|
+
* Added the :gem rake task.
|
19
|
+
* Minor gemspec updates.
|
20
|
+
* Some minor test suite updates.
|
21
|
+
|
22
|
+
== 1.6.2 - 4-Aug-2009
|
23
|
+
* Now compatible with Ruby 1.9.x.
|
24
|
+
* License changed to Artistic 2.0.
|
25
|
+
* Added the Pathname.pwd method as a synonym for Pathname.new(Dir.pwd).
|
26
|
+
* Modified Pathname#dirname so that you can specify a level that indicates
|
27
|
+
how many levels up you want to retrieve. For example, if your path was
|
28
|
+
'/usr/local/bin', then path.dirname(2) would return '/usr'.
|
29
|
+
* Now compatible with Ruby 1.9.x.
|
30
|
+
* Bumped required version of the facade library to 1.0.4.
|
31
|
+
|
32
|
+
== 1.6.1 - 8-Nov-2008
|
33
|
+
* Added the Pathname#[] method, which accepts an index, an index plus a
|
34
|
+
length, or a range, and returns appropriate the path element(s).
|
35
|
+
* Refactoring the platform checking in the test suite to use rbconfig instead
|
36
|
+
of RUBY_PLATFORM.
|
37
|
+
* More inline documentation examples.
|
38
|
+
|
39
|
+
== 1.6.0 - 13-July-2008
|
40
|
+
* The facade for ftools (and ftools itself) has been removed. The ftools
|
41
|
+
library is deprecated in favor of FileUtils.
|
42
|
+
* PathnameError is now Pathname::Error.
|
43
|
+
* Bug fix for Pathname#relative_path_from for MS Windows. Thanks go to an
|
44
|
+
anonymous user for the spot.
|
45
|
+
* Fixed a bug where frozen strings would raise an error on MS Windows.
|
46
|
+
* The code is now -w clean.
|
47
|
+
* Removed the C version as part of the release because it was just too
|
48
|
+
difficult to maintain both versions. The C code remains in CVS, however.
|
49
|
+
* Changed platform checking to use rbconfig instead of RUBY_PLATFORM to avoid
|
50
|
+
potential issues with other Ruby implementation.
|
51
|
+
|
52
|
+
== 1.5.2 - 9-Mar-2007
|
53
|
+
* Bug fix for the Pathname#realpath method where it was not handling recursive
|
54
|
+
symlinks. The C version was also fixed, but it only affected platforms that
|
55
|
+
don't have the realpath() function.
|
56
|
+
* Added a test for recursive symlinks (for Solaris, anyway).
|
57
|
+
* Updated the docs for Pathname#realpath.
|
58
|
+
* Minor speed enhancements for the C version and the elimination of one
|
59
|
+
(potential) segfault.
|
60
|
+
* Added a 'Future Plans' section to the README.
|
61
|
+
* Added a Rakefile. You can now build, clean, and test and install (both the
|
62
|
+
pure Ruby and C versions).
|
63
|
+
|
64
|
+
== 1.5.1 - 28-Aug-2006
|
65
|
+
* Added the Kernel#pn method as a shortcut for Pathname.new.
|
66
|
+
* The Pathname#readlink now properly handles symbolic links. The 'fix'
|
67
|
+
from 1.4.4 did not work.
|
68
|
+
* The C extension uses your system's realpath() function for the
|
69
|
+
Pathname#readlink method if it has one.
|
70
|
+
* Added the '/' alias for '+'. So, p1 / p2 is the same as p1 + p2.
|
71
|
+
* The windows-pr package is now required on MS Windows.
|
72
|
+
|
73
|
+
== 1.5.0 - 17-Apr-2006
|
74
|
+
* Better subclass handling, in that some methods that previously returned
|
75
|
+
hardcoded Pathname.new now return self.class.new.
|
76
|
+
* File URL's are now handled on Unix as well (using the 'uri' package).
|
77
|
+
* Some comment changes/clarifications.
|
78
|
+
* Added the PathnameError class to the pure Ruby version.
|
79
|
+
|
80
|
+
== 1.4.4 - 23-Mar-2006
|
81
|
+
* If the path is a symbolic link the Pathname#realpath method
|
82
|
+
now returns the absolute path of that link, i.e. the result
|
83
|
+
of File.readlink (as a Pathname object).
|
84
|
+
|
85
|
+
== 1.4.3 - 3-Mar-2006
|
86
|
+
* Added the Pathname#realpath method.
|
87
|
+
|
88
|
+
== 1.4.2 - 22-Feb-2006
|
89
|
+
* Fixed the Pathname#relative_path_from method for Windows. This really only
|
90
|
+
affected edge cases that you probably never saw anyway.
|
91
|
+
* Added corresponding tests for Windows.
|
92
|
+
|
93
|
+
== 1.4.1 - 18-Feb-2006
|
94
|
+
* Added the Pathname#parent method.
|
95
|
+
* Added the Pathname#relative_path_from method.
|
96
|
+
* Bug fix for Pathname#pstrip on *nix.
|
97
|
+
* Corresponding test suite additions.
|
98
|
+
|
99
|
+
== 1.4.0 - 19-Dec-2005
|
100
|
+
* Added destructive and non-destructive methods for some methods - pstrip,
|
101
|
+
pstrip!, undecorate, undecorate!, clean and clean!.
|
102
|
+
* Added a C extension version of this package. You can use the C version
|
103
|
+
instead of the pure Ruby version instead. See the README for more details.
|
104
|
+
* Fixed bug in the root method where the result wasn't guaranteed to be a
|
105
|
+
Pathname class.
|
106
|
+
* Fixed bugs in Windows version where the receiver was inadvertantly modified
|
107
|
+
in some cases, and added tests to check for this in the future.
|
108
|
+
* Modified the Dir.glob facade so that it (temporarily) changes to the path
|
109
|
+
directory, globs on that path, then returns to the original directory.
|
110
|
+
* Added the bench_pathname.rb script to let you benchmark all Pathname
|
111
|
+
methods.
|
112
|
+
|
113
|
+
== 1.3.1 - 21-Nov-2005
|
114
|
+
* Added the Pathname#children method.
|
115
|
+
* Added tests for the Pathname#children method.
|
116
|
+
|
117
|
+
== 1.3.0 - 28-Oct-2005
|
118
|
+
* Added the short_path and long_path methods for MS Windows.
|
119
|
+
* Optimization for the '+' method on Unix.
|
120
|
+
* Added some examples under the 'examples' directory.
|
121
|
+
* More tests added and some minor changes to the test suite in general.
|
122
|
+
|
123
|
+
== 1.2.1 - 1-Sep-2005
|
124
|
+
* Bug fix for the ascend and descend methods wrt Windows and UNC paths.
|
125
|
+
* More tests added for ascend and descend methods.
|
126
|
+
|
127
|
+
== 1.2.0 - 29-Aug-2005
|
128
|
+
* Added the 'ascend' and 'descend' methods.
|
129
|
+
* Added corresponding test suite additions.
|
130
|
+
|
131
|
+
== 1.1.0 - 13-Jul-2005
|
132
|
+
* Added the 'find' facade.
|
133
|
+
|
134
|
+
== 1.0.0 - 11-Jun-2005
|
135
|
+
* 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
|