Sha256: 1c2d9bd18da38d109c1a7849779f704e43b6f564a22662cda0b78c7e12165f59

Contents?: true

Size: 1.06 KB

Versions: 19

Compression:

Stored size: 1.06 KB

Contents

require 'tempfile'

module Dpl
  class Zip < Struct.new(:src, :dest, :opts)
    ZIP_EXT = %w(.zip .jar)

    def initialize(*)
      require 'zip'
      super
    end

    def zip
      if zip_file?
        File.new(src)
      elsif dir?
        zip_dir
      else
        zip_file
      end
    end

    def zip_dir
      create(Dir.glob(*glob).reject { |path| dir?(path) })
    end

    def zip_file
      create([src])
    end

    def create(files)
      ::Zip::File.open(dest, ::Zip::File::CREATE) do |zip|
        files.each do |file|
          zip.add(file.sub("#{src}/", ''), file)
        end
      end
      File.new(dest)
    end

    def zip_file?
      exts.include?(File.extname(src))
    end

    def dir?(path = src)
      File.directory?(path)
    end

    def copy
      FileUtils.cp(src, dest)
    end

    def glob
      glob = ["#{src}/**/*"]
      glob << File::FNM_DOTMATCH if dot_match?
      glob
    end

    def dot_match?
      opts[:dot_match]
    end

    def exts
      opts[:exts] ||= ZIP_EXT
    end

    def opts
      super || {}
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
dpl-2.0.3.beta.4 lib/dpl/helper/zip.rb
dpl-2.0.3.beta.3 lib/dpl/helper/zip.rb
dpl-2.0.3.beta.2 lib/dpl/helper/zip.rb
dpl-2.0.3.beta.1 lib/dpl/helper/zip.rb
dpl-2.0.2.beta.1 lib/dpl/helper/zip.rb
dpl-2.0.0.beta.3 lib/dpl/helper/zip.rb
dpl-2.0.0.beta.2 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.14 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.13 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.12 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.11 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.10 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.9 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.8 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.7 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.6 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.5 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.2 lib/dpl/helper/zip.rb
dpl-2.0.0.alpha.1 lib/dpl/helper/zip.rb