pathname2 1.3.0 → 1.3.1

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 CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.3.1 - 21-Nov-2005
2
+ * Added the Pathname#children method.
3
+ * Added tests for the Pathname#children method.
4
+
1
5
  == 1.3.0 - 28-Oct-2005
2
6
  * Added the short_path and long_path methods for MS Windows.
3
7
  * Optimization for the '+' method on Unix.
data/MANIFEST CHANGED
@@ -4,6 +4,9 @@ README
4
4
  install.rb
5
5
  pathname2.gempsec
6
6
 
7
+ examples/bench_plus.rb
8
+ examples/example_pathname.rb
9
+
7
10
  lib/pathname2.rb
8
11
 
9
12
  test/tc_pathname.rb
data/README CHANGED
@@ -17,7 +17,7 @@
17
17
  gem install pathname2-<version>.gem
18
18
 
19
19
  == Synopsis
20
- require "pathname"
20
+ require "pathname2"
21
21
 
22
22
  # Unix
23
23
  path1 = "/foo/bar/baz"
data/lib/pathname2.rb CHANGED
@@ -75,7 +75,7 @@ class Pathname < String
75
75
  Win32API.new("shlwapi", "PathRemoveBackslash", "P", "P")
76
76
  end
77
77
 
78
- VERSION = "1.3.0"
78
+ VERSION = "1.3.1"
79
79
  MAX_PATH = 260
80
80
 
81
81
  # Creates and returns a new Pathname object.
@@ -108,6 +108,28 @@ class Pathname < String
108
108
  super(path)
109
109
  end
110
110
 
111
+ # Returns the children of the directory, files and subdirectories, as an
112
+ # array of Pathname objects. If you set +with_directory+ to +false+, then
113
+ # the returned pathnames will contain the filename only.
114
+ #
115
+ # Note that the result never contain the entries '.' and '..' in the
116
+ # the directory because they are not children. Also note that this method
117
+ # is *not* recursive.
118
+ #
119
+ def children(with_directory = true)
120
+ with_directory = false if self == '.'
121
+ result = []
122
+ Dir.foreach(self) { |file|
123
+ next if file == '.' || file == '..'
124
+ if with_directory
125
+ result << Pathname.new(File.join(self, file))
126
+ else
127
+ result << Pathname.new(file)
128
+ end
129
+ }
130
+ result
131
+ end
132
+
111
133
  # Win32 only
112
134
  #
113
135
  # Removes the decoration from a path string. For example,
data/test/tc_pathname.rb CHANGED
@@ -41,7 +41,7 @@ class TC_Pathname < Test::Unit::TestCase
41
41
  end
42
42
 
43
43
  def test_version
44
- assert_equal("1.3.0", Pathname::VERSION)
44
+ assert_equal("1.3.1", Pathname::VERSION)
45
45
  end
46
46
 
47
47
  def test_ascend
@@ -82,6 +82,36 @@ class TC_Pathname < Test::Unit::TestCase
82
82
  assert_equal(3, @rel_array.length)
83
83
  end
84
84
 
85
+ def test_children
86
+ Dir.chdir("..") if File.basename(Dir.pwd) == "test"
87
+ @cur_path = Pathname.new(Dir.pwd)
88
+
89
+ assert_respond_to(@cur_path, :children)
90
+ assert_nothing_raised{ @cur_path.children }
91
+ assert_kind_of(Array, @cur_path.children)
92
+
93
+ assert_equal(
94
+ [
95
+ Dir.pwd + "/CHANGES",
96
+ Dir.pwd + "/MANIFEST",
97
+ Dir.pwd + "/README",
98
+ Dir.pwd + "/install.rb",
99
+ Dir.pwd + "/pathname2.gemspec",
100
+ Dir.pwd + "/examples",
101
+ Dir.pwd + "/lib",
102
+ Dir.pwd + "/test"
103
+ ],
104
+ @cur_path.children
105
+ )
106
+ assert_equal(
107
+ [
108
+ "CHANGES","MANIFEST","README","install.rb",
109
+ "pathname2.gemspec","examples", "lib", "test"
110
+ ],
111
+ @cur_path.children(false)
112
+ )
113
+ end
114
+
85
115
  def test_unc
86
116
  assert_raises(NotImplementedError){ @abs_path.unc? }
87
117
  end
@@ -34,7 +34,7 @@ class TC_Pathname_MSWin < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  def test_version
37
- assert_equal("1.3.0", Pathname::VERSION)
37
+ assert_equal("1.3.1", Pathname::VERSION)
38
38
  end
39
39
 
40
40
  # Convenience method for test_plus
@@ -295,6 +295,36 @@ class TC_Pathname_MSWin < Test::Unit::TestCase
295
295
  assert_kind_of(Pathname, f)
296
296
  }
297
297
  end
298
+
299
+ def test_children
300
+ Dir.chdir("..") if File.basename(Dir.pwd) == "test"
301
+ @cur_path = Pathname.new(Dir.pwd)
302
+
303
+ assert_respond_to(@cur_path, :children)
304
+ assert_nothing_raised{ @cur_path.children }
305
+ assert_kind_of(Array, @cur_path.children)
306
+
307
+ assert_equal(
308
+ [
309
+ Dir.pwd + "/CHANGES",
310
+ Dir.pwd + "/examples",
311
+ Dir.pwd + "/install.rb",
312
+ Dir.pwd + "/lib",
313
+ Dir.pwd + "/MANIFEST",
314
+ Dir.pwd + "/pathname2.gemspec",
315
+ Dir.pwd + "/README",
316
+ Dir.pwd + "/test"
317
+ ].map{ |e| e.tr("/","\\") },
318
+ @cur_path.children
319
+ )
320
+ assert_equal(
321
+ [
322
+ "CHANGES","examples","install.rb","lib",
323
+ "MANIFEST", "pathname2.gemspec", "README", "test"
324
+ ],
325
+ @cur_path.children(false)
326
+ )
327
+ end
298
328
 
299
329
  def teardown
300
330
  @fpath = nil
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: pathname2
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.3.0
7
- date: 2005-10-26 00:00:00 -06:00
6
+ version: 1.3.1
7
+ date: 2005-11-21 00:00:00 -07:00
8
8
  summary: An alternate implementation of the Pathname class
9
9
  require_paths:
10
10
  - lib