Module: FeduxOrgStdlib::Zipper
- Defined in:
- lib/fedux_org_stdlib/zipper.rb
Class Method Summary collapse
- .unzip(source_file, destination_directory = Dir.getwd) ⇒ Object
- .zip(source_directory, destination_file, prefix: '', executables: []) ⇒ Object
Class Method Details
.unzip(source_file, destination_directory = Dir.getwd) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fedux_org_stdlib/zipper.rb', line 7 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 |
.zip(source_directory, destination_file, prefix: '', executables: []) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fedux_org_stdlib/zipper.rb', line 20 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 |