Class: Buildr::ArchiveTask::ZipExpander

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

Overview

Extend one Zip file into another.

Instance Method Summary collapse

Constructor Details

#initialize(zip_file) ⇒ ZipExpander

:nodoc:



240
241
242
243
244
# File 'lib/buildr/packaging/archive.rb', line 240

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

Instance Method Details

#exclude(*files) ⇒ Object



252
253
254
255
# File 'lib/buildr/packaging/archive.rb', line 252

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

#expand(file_map, path) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/buildr/packaging/archive.rb', line 257

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) } &&
         !@excludes.any? { |pattern| File.fnmatch(pattern, entry.name) }
        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: <<



246
247
248
249
# File 'lib/buildr/packaging/archive.rb', line 246

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