samples/example_recursive.rb in rubyzip-1.2.1 vs samples/example_recursive.rb in rubyzip-1.2.2

- old
+ new

@@ -17,39 +17,38 @@ @output_file = output_file end # Zip the input directory. def write - entries = Dir.entries(@input_dir) - %w(. ..) + entries = Dir.entries(@input_dir) - %w[. ..] - ::Zip::File.open(@output_file, ::Zip::File::CREATE) do |io| - write_entries entries, '', io + ::Zip::File.open(@output_file, ::Zip::File::CREATE) do |zipfile| + write_entries entries, '', zipfile end end private # A helper method to make the recursion work. - def write_entries(entries, path, io) + def write_entries(entries, path, zipfile) entries.each do |e| - zip_file_path = path == '' ? e : File.join(path, e) - disk_file_path = File.join(@input_dir, zip_file_path) - puts "Deflating #{disk_file_path}" + zipfile_path = path == '' ? e : File.join(path, e) + disk_file_path = File.join(@input_dir, zipfile_path) if File.directory? disk_file_path - recursively_deflate_directory(disk_file_path, io, zip_file_path) + recursively_deflate_directory(disk_file_path, zipfile, zipfile_path) else - put_into_archive(disk_file_path, io, zip_file_path) + put_into_archive(disk_file_path, zipfile, zipfile_path) end end end - def recursively_deflate_directory(disk_file_path, io, zip_file_path) - io.mkdir zip_file_path - subdir = Dir.entries(disk_file_path) - %w(. ..) - write_entries subdir, zip_file_path, io + def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path) + zipfile.mkdir zipfile_path + subdir = Dir.entries(disk_file_path) - %w[. ..] + write_entries subdir, zipfile_path, zipfile end - def put_into_archive(disk_file_path, io, zip_file_path) - io.add(zip_file_path, disk_file_path) + def put_into_archive(disk_file_path, zipfile, zipfile_path) + zipfile.add(zipfile_path, disk_file_path) end end