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:



276
277
278
279
280
# File 'lib/buildr/packaging/archive.rb', line 276

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

Instance Method Details

#exclude(*files) ⇒ Object



288
289
290
291
# File 'lib/buildr/packaging/archive.rb', line 288

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

#expand(file_map, path) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/buildr/packaging/archive.rb', line 293

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: <<



282
283
284
285
# File 'lib/buildr/packaging/archive.rb', line 282

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