A drop-in replacement for the current Pathname class.
* Ruby 1.8.0 or later * facade 1.0.0 or later (available on the RAA and as a gem) * windows-pr 0.5.1 or later (available on the RAA and as a gem) The windows-pr library is only required on MS Windows.
rake test (optional) rake install
rake test (optional) gem install pathname2-<version>.gem
rake test_c (optional) rake install_c
require "pathname2" # Unix path1 = "/foo/bar/baz" path2 = "../zap" path1 + path2 # "/foo/bar/zap" path1 / path2 # "/foo/bar/zap" (same as +) path1.exists? # Does this path exist? path1.dirname # "/foo/bar" path1.to_a # ['foo','bar','baz'] # Windows path1 = "C:/foo/bar/baz" path2 = "../zap" path1 + path2 # "C:\\foo\\bar\\zap" path1.root # "C:\\" path1.to_a # ['C:','foo','bar','baz']
All forward slashes are converted to backslashes for Pathname objects.
If your pathname consists solely of ".", or "..", the return value for Pathname#clean will be different. On Win32, "\\" is returned, while on Unix "." is returned. I consider this an extreme edge case and will not worry myself with it.
* It is a subclass of String (and thus, mixes in Enumerable). * It has sensical to_a and root instance methods. * It works on Windows and Unix. The current implementation does not work with Windows path names very well, and not at all when it comes to UNC paths. * The Pathname#cleanpath method works differently - it always returns a canonical pathname. In addition, there is no special consideration for symlinks (yet), though I'm not sure it warrants it. * The Pathname#+ method auto cleans. * It uses a facade for all File and Dir methods, as well as most FileUtils methods. * Pathname#clean works slightly differently. In the stdlib version, Pathname#clean("../a") returns "../a". In this version, it returns "a". This affects other methods, such as Pathname#relative_path_from. * Accepts file urls and converts them to paths automatically, e.g. file:///foo%20bar/baz becomes '/foo/bar/baz'. * Adds a Kernel level +pn+ method as a shortcut. * Allows you to add paths together with the '/' operator.
Because there is some overlap in method names between File, Dir, and FileUtils, the priority is as follows: * File * Dir * FileUtils In other words, whichever of these defines a given method first is the method that is used by the pathname2 library.
In Ruby 1.8.3 and 1.8.4 you will see a failure in the test suite regarding 'fu_world_writable?' from FileUtils. You can ignore this. That method is supposed to be private. See ruby-core:7383. Any other issues should be reported on the project page at http://www.rubyforge.org/projects/shards
Suggestions welcome.
Artistic 2.0
(C) 2003-2009 Daniel J. Berger All rights reserved.
This library is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
Daniel J. Berger
Generated with the Darkfish Rdoc Generator 2.