lib/vfs/entries/dir.rb in vfs-0.3.8 vs lib/vfs/entries/dir.rb in vfs-0.3.9

- old
+ new

@@ -90,16 +90,21 @@ # # Content # - def entries options = {}, &block + def entries *args, &block + raise "invalid arguments #{args.inspect}!" if args.size > 2 + options = args.last.is_a?(Hash) ? args.pop : {} + query = args.first options[:bang] = true unless options.include? :bang + storage.open_fs do |fs| begin list = [] - fs.each_entry path do |name, type| + # query option is optional and supported only for some storages (local fs for example) + fs.each_entry path, query do |name, type| next if options[:filter] and options[:filter] != type entry = if type == :dir dir(name) elsif type == :file file(name) @@ -123,17 +128,23 @@ end end end alias_method :each, :entries - def files options = {}, &block + def files *args, &block + options = args.last.is_a?(Hash) ? args.pop : {} + options[:filter] = :file - entries options, &block + args << options + entries *args, &block end - def dirs options = {}, &block + def dirs *args, &block + options = args.last.is_a?(Hash) ? args.pop : {} + options[:filter] = :dir - entries options, &block + args << options + entries *args, &block end def include? name entry[name].exist? end \ No newline at end of file