Sha256: 42f7d401e556c948ecf2f7e3b64006584a4aeb256f33220fd126b47eb3f6052e

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 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)
      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

2 entries across 2 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.11.9 lib/fedux_org_stdlib/zipper.rb
fedux_org-stdlib-0.11.8 lib/fedux_org_stdlib/zipper.rb