Class: Buildr::ArchiveTask::ZipExpander
- Defined in:
- lib/buildr/packaging/archive.rb
Overview
Extend one Zip file into another.
Instance Method Summary collapse
- #concatenate(*files) ⇒ Object
- #exclude(*files) ⇒ Object
- #expand(file_map, transform_map, path) ⇒ Object
- #include(*files) ⇒ Object (also: #<<)
-
#initialize(zip_file) ⇒ ZipExpander
constructor
:nodoc:.
- #transform(*files, &block) ⇒ Object
Constructor Details
#initialize(zip_file) ⇒ ZipExpander
:nodoc:
286 287 288 289 290 291 292 |
# File 'lib/buildr/packaging/archive.rb', line 286 def initialize(zip_file) @zip_file = zip_file.to_s @includes = [] @excludes = [] @concatenates = [] @transforms = {} end |
Instance Method Details
#concatenate(*files) ⇒ Object
305 306 307 308 |
# File 'lib/buildr/packaging/archive.rb', line 305 def concatenate(*files) @concatenates |= files self end |
#exclude(*files) ⇒ Object
300 301 302 303 |
# File 'lib/buildr/packaging/archive.rb', line 300 def exclude(*files) @excludes |= files self end |
#expand(file_map, transform_map, path) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/buildr/packaging/archive.rb', line 315 def (file_map, transform_map, path) @includes = ['*'] if @includes.empty? Zip::File.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}" if @concatenates.any? { |pattern| File.fnmatch(pattern, entry.name) } file_map[dest] << ZipEntryData.new(source, entry) elsif @transforms.each_pair.detect do |transform, transform_block|\ if transform.any? { |pattern| File.fnmatch(pattern, entry.name) } file_map[dest] << ZipEntryData.new(source, entry) transform_map[dest] = transform_block true end end else file_map[dest] = ZipEntryData.new(source, entry) end end end end end |
#include(*files) ⇒ Object Also known as: <<
294 295 296 297 |
# File 'lib/buildr/packaging/archive.rb', line 294 def include(*files) @includes |= files self end |
#transform(*files, &block) ⇒ Object
310 311 312 313 |
# File 'lib/buildr/packaging/archive.rb', line 310 def transform(*files, &block) @transforms[[files].flatten] = block self end |