Browse files

add Pathname.glob_files

  • Loading branch information...
1 parent 667292e commit 21dd68b808db875ba78215b3b6af60bb11c1a615 @quix committed Aug 9, 2009
Showing with 17 additions and 0 deletions.
  1. +4 −0 lib/quix/ext/pathname.rb
  2. +13 −0 test/test_pathname.rb
View
4 lib/quix/ext/pathname.rb
@@ -97,5 +97,9 @@ def glob_all(pattern, flags = 0, &block)
path.basename =~ %r!\A\.\.?\Z!
}
end
+
+ def glob_files(*args)
+ glob_all(*args).select { |file| file.file? }
+ end
end
end
View
13 test/test_pathname.rb
@@ -130,6 +130,19 @@ def test_glob_all
assert_equal all_files.sort, Pathname.glob_all(data_dir + "*").sort
end
+ def test_glob_files
+ data_dir = Pathname(DATA_DIR)
+
+ s = %w[a .b .c d].map { |t| data_dir + t }
+ touch s[0]
+ mkdir s[1]
+ touch s[2]
+ mkdir s[3]
+
+ assert_equal s.sort, Pathname.glob_all(data_dir + "*").sort
+ assert_equal [s[0], s[2]].sort, Pathname.glob_files(data_dir + "*").sort
+ end
+
if File::ALT_SEPARATOR == "\\"
def test_initialize
assert_equal "a/b/c", Pathname("a\\b\\c").to_s

0 comments on commit 21dd68b

Please sign in to comment.