Class: Buildr::ArchiveTask::ZipExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/buildr/packaging/zip.rb

Overview

Extend one Zip file into another.

Instance Method Summary collapse

Constructor Details

#initialize(zip_file) ⇒ ZipExpander

:nodoc:



198
199
200
201
202
# File 'lib/buildr/packaging/zip.rb', line 198

def initialize(zip_file)
  @zip_file = zip_file.to_s
  @includes = []
  @excludes = []
end

Instance Method Details

#exclude(*files) ⇒ Object



210
211
212
213
# File 'lib/buildr/packaging/zip.rb', line 210

def exclude(*files)
  @excludes |= files
  self
end

#expand(file_map, path) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/buildr/packaging/zip.rb', line 215

def expand(file_map, path)
  @includes = ['**/*'] if @includes.empty?
  Zip::ZipFile.open(@zip_file) do |source|
    source.entries.reject { |entry| entry.directory? }.each do |entry|
      if @includes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) } &&
         !@excludes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) }
        dest = path =~ /^\/?$/ ? entry.name : Util.relative_path(path + "/" + entry.name)
        trace "Adding #{dest}"
        file_map[dest] = lambda { |output| output.write source.read(entry) }
      end
    end
  end
end

#include(*files) ⇒ Object Also known as: <<



204
205
206
207
# File 'lib/buildr/packaging/zip.rb', line 204

def include(*files)
  @includes |= files
  self
end