Sha256: 5af52989f4de8bce090af7222e94c86ab6a345116f716e9425ce4ea0265ee5fa
Contents?: true
Size: 1.18 KB
Versions: 7
Compression:
Stored size: 1.18 KB
Contents
# encoding: utf-8 require 'fedux_org_stdlib/require_files' require_library %w(zip zip/filesystem active_support/core_ext/object/blank) module FeduxOrgStdlib module Zipper def unzip(source_file, destination_directory = Dir.getwd) return unless destination_directory Zip::File.open(source_file) do |z| z.each do |e| new_path = File.join(destination_directory, e.name) FileUtils.mkdir_p File.dirname(new_path) e.extract(new_path) end end end def zip(source_directory, destination_file, prefix: '', executables: []) Zip::File.open(destination_file, Zip::File::CREATE) do |z| Dir.glob(File.join(source_directory, '**', '*')).each do |filename| paths = [] paths << Pathname.new(prefix) unless prefix.blank? paths << Pathname.new(filename).relative_path_from(Pathname.new(source_directory)) z.add(File.join(*paths), filename) z.file.chmod(0755, File.join(*paths)) if File.executable? filename z.file.chmod(0755, File.join(*paths)) if executables.any? { |f| Regexp.new(f) === filename } end end end module_function :zip, :unzip end end
Version data entries
7 entries across 7 versions & 1 rubygems