pathname2 1.7.1 → 1.7.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a45bf8835ded8326c6c8d0667803b5ddfc1ce513
4
- data.tar.gz: bddb0aa47ca5a98b5e513d0203e1ed9b086d3ef5
3
+ metadata.gz: 8eca512f0553c41d9258bf2b4bb6e5fb8a0eac4e
4
+ data.tar.gz: 5e96c3fbd0a6be1644a8e567786e040529f2cef2
5
5
  SHA512:
6
- metadata.gz: a86e59426f9e6c587859d464616d968671764581615e519775ee9f3150237c170eaeb7311999ddf557e2ebe55fed5d5a0220d967f386ca9be5e1677ab3982307
7
- data.tar.gz: 2e8b806858a9c318e8b7704981208d848ffadf08d589bcdde4277ef409b8d49e39255b20b14667bb0e1cfa02780b133b63107a4406d2bf1572ad7c9fb6dcb2c2
6
+ metadata.gz: 90f5e288f86becab946179f1e2270bfb642cd267ea487cf31b4f617304912377da722e1196d324e1f408d0af2836d156a78e2711428abcfaed71338338b7d5ac
7
+ data.tar.gz: 982627ffc369693216c45d976f7ff6a76572aa83a973e601cd5ceb5c534fd27a3bef2e7f99425bcdcf3654017a34c2b1d4ff0898fa2d487845bb21ab48613d4e
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ == 1.7.2 - 23-Apr-2014
2
+ * The join and expand_path methods now return Pathname objects.
3
+
1
4
  == 1.7.1 - 28-Mar-2014
2
5
  * Updated gemspec for Windows vs Unix.
3
6
  * Updated README and MANIFEST.
data/README CHANGED
@@ -14,8 +14,8 @@
14
14
  require 'pathname2'
15
15
 
16
16
  # Unix
17
- path1 = "/foo/bar/baz"
18
- path2 = "../zap"
17
+ path1 = Pathname.new("/foo/bar/baz")
18
+ path2 = Pathname.new("../zap")
19
19
 
20
20
  path1 + path2 # "/foo/bar/zap"
21
21
  path1 / path2 # "/foo/bar/zap" (same as +)
@@ -24,8 +24,8 @@
24
24
  path1.to_a # ['foo','bar','baz']
25
25
 
26
26
  # Windows
27
- path1 = "C:/foo/bar/baz"
28
- path2 = "../zap"
27
+ path1 = Pathname.new("C:/foo/bar/baz")
28
+ path2 = Pathname.new("../zap")
29
29
 
30
30
  path1 + path2 # "C:\\foo\\bar\\zap"
31
31
  path1.root # "C:\\"
data/Rakefile CHANGED
@@ -132,6 +132,12 @@ namespace :test do
132
132
  t.verbose = true
133
133
  t.test_files = FileList["test/#{dir}/test_is_unc.rb"]
134
134
  end
135
+
136
+ Rake::TestTask.new(:join) do |t|
137
+ t.warning = true
138
+ t.verbose = true
139
+ t.test_files = FileList["test/#{dir}/test_join.rb"]
140
+ end
135
141
 
136
142
  Rake::TestTask.new(:long_path) do |t|
137
143
  t.warning = true
data/lib/pathname2.rb CHANGED
@@ -93,7 +93,7 @@ class Pathname < String
93
93
  public
94
94
 
95
95
  # The version of the pathname2 library
96
- VERSION = '1.7.1'
96
+ VERSION = '1.7.2'
97
97
 
98
98
  # The maximum length of a path
99
99
  MAXPATH = 1024 unless defined? MAXPATH # Yes, I willfully violate POSIX
@@ -813,6 +813,26 @@ class Pathname < String
813
813
  local_path
814
814
  end
815
815
 
816
+ # Joins the given pathnames onto +self+ to create a new Pathname object.
817
+ #
818
+ # path = Pathname.new("C:/Users")
819
+ # path = path.join("foo", "Downloads") # => C:/Users/foo/Downloads
820
+ #
821
+ def join(*args)
822
+ args.unshift self
823
+ result = args.pop
824
+ result = self.class.new(result) unless result === self.class
825
+ return result if result.absolute?
826
+
827
+ args.reverse_each{ |path|
828
+ path = self.class.new(path) unless path === self.class
829
+ result = path + result
830
+ break if result.absolute?
831
+ }
832
+
833
+ result
834
+ end
835
+
816
836
  # A custom pretty printer
817
837
  def pretty_print(q)
818
838
  if File::ALT_SEPARATOR
@@ -972,12 +992,7 @@ class Pathname < String
972
992
 
973
993
  # File.expand_path
974
994
  def expand_path(*args)
975
- File.expand_path(self, *args)
976
- end
977
-
978
- # File.join
979
- def join(*args)
980
- File.join(self, *args)
995
+ self.class.new(File.expand_path(self, *args))
981
996
  end
982
997
 
983
998
  #--
data/pathname2.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'pathname2'
5
- spec.version = '1.7.1'
5
+ spec.version = '1.7.2'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
data/test/test_version.rb CHANGED
@@ -8,6 +8,6 @@ require 'test-unit'
8
8
 
9
9
  class TC_Pathname_Version < Test::Unit::TestCase
10
10
  test "version is set to expected value" do
11
- assert_equal('1.7.1', Pathname::VERSION)
11
+ assert_equal('1.7.2', Pathname::VERSION)
12
12
  end
13
13
  end
@@ -0,0 +1,52 @@
1
+ ########################################################################
2
+ # test_join.rb
3
+ #
4
+ # Test suite for the Pathname#join method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Join < Test::Unit::TestCase
10
+ def setup
11
+ @apath = Pathname.new("C:\\foo\\bar")
12
+ @rpath = Pathname.new("foo\\bar\\baz")
13
+ end
14
+
15
+ def assert_pathname_join(final, initial, *rest)
16
+ a = Pathname.new(final)
17
+ b = Pathname.new(initial)
18
+ assert_equal(a, b.join(*rest))
19
+ end
20
+
21
+ test "join method accepts one or more arguments" do
22
+ assert_nothing_raised{ @apath.join("foo") }
23
+ assert_nothing_raised{ @apath.join("foo", "bar") }
24
+ assert_nothing_raised{ @apath.join("foo", "bar", "baz") }
25
+ end
26
+
27
+ test "join method returns expected results when joining relative paths to an absolute path" do
28
+ assert_pathname_join("C:\\foo", "C:\\", "foo")
29
+ assert_pathname_join("C:\\foo\\bar", "C:\\foo", "bar")
30
+ assert_pathname_join("C:\\foo\\bar\\baz", "C:\\foo", "bar", "baz")
31
+ end
32
+
33
+ test "join method returns expected results when joining relative paths to a relative path" do
34
+ assert_pathname_join("foo\\bar", "foo", "bar")
35
+ assert_pathname_join("foo\\bar\\baz", "foo", "bar", "baz")
36
+ end
37
+
38
+ test "join method returns expected results when joining an absolute path to an absolute path" do
39
+ assert_pathname_join("D:\\", "C:\\", "D:\\")
40
+ assert_pathname_join("D:\\foo", "C:\\", "D:\\", "foo")
41
+ assert_pathname_join("D:\\", "C:\\", "foo", "bar", "D:\\")
42
+ end
43
+
44
+ test "join returns an instance of Pathname" do
45
+ assert_kind_of(Pathname, @apath.join("foo"))
46
+ end
47
+
48
+ def teardown
49
+ @apath = nil
50
+ @rpath = nil
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathname2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-28 00:00:00.000000000 Z
11
+ date: 2014-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facade
@@ -94,6 +94,7 @@ files:
94
94
  - test/windows/test_is_relative.rb
95
95
  - test/windows/test_is_root.rb
96
96
  - test/windows/test_is_unc.rb
97
+ - test/windows/test_join.rb
97
98
  - test/windows/test_long_path.rb
98
99
  - test/windows/test_misc.rb
99
100
  - test/windows/test_parent.rb