Add extended globbing support

This commit is contained in:
David Rodríguez 2016-10-08 19:32:53 -03:00
parent 6597af1257
commit 9c475f5160
2 changed files with 12 additions and 1 deletions

View File

@ -57,7 +57,7 @@ module Zip
@entry_set[to_key(entry.parent_as_string)] @entry_set[to_key(entry.parent_as_string)]
end end
def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH) def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB)
entries.map do |entry| entries.map do |entry|
next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags) next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
yield(entry) if block_given? yield(entry) if block_given?

View File

@ -149,4 +149,15 @@ class ZipEntrySetTest < MiniTest::Test
# assert_equal(entries.size, res.size) # assert_equal(entries.size, res.size)
# assert_equal(entrySet.map { |e| e.name }, res.map { |e| e.name }) # assert_equal(entrySet.map { |e| e.name }, res.map { |e| e.name })
end end
def test_glob3
entries = [
::Zip::Entry.new('zf.zip', 'a/a'),
::Zip::Entry.new('zf.zip', 'a/b'),
::Zip::Entry.new('zf.zip', 'a/c')
]
entrySet = ::Zip::EntrySet.new(entries)
assert_equal(entries[0, 2].sort, entrySet.glob('a/{a,b}').sort)
end
end end