Skip to content

Commit

Permalink
add Pathname.glob_files
Browse files Browse the repository at this point in the history
  • Loading branch information
quix committed Aug 23, 2009
1 parent 667292e commit 21dd68b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/quix/ext/pathname.rb
Expand Up @@ -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
13 changes: 13 additions & 0 deletions test/test_pathname.rb
Expand Up @@ -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
Expand Down

0 comments on commit 21dd68b

Please sign in to comment.