diff --git a/lib/quix/ext/pathname.rb b/lib/quix/ext/pathname.rb index c789c90..57adde2 100644 --- a/lib/quix/ext/pathname.rb +++ b/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 diff --git a/test/test_pathname.rb b/test/test_pathname.rb index 2e0a477..4cfd7bf 100644 --- a/test/test_pathname.rb +++ b/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