Class: Buildr::ArchiveTask::ZipExpander
- Defined in:
- lib/buildr/packaging/archive.rb
Overview
Extend one Zip file into another.
Instance Method Summary collapse
- #exclude(*files) ⇒ Object
- #expand(file_map, path) ⇒ Object
- #include(*files) ⇒ Object (also: #<<)
-
#initialize(zip_file) ⇒ ZipExpander
constructor
:nodoc:.
Constructor Details
#initialize(zip_file) ⇒ ZipExpander
:nodoc:
238 239 240 241 242 |
# File 'lib/buildr/packaging/archive.rb', line 238 def initialize(zip_file) @zip_file = zip_file.to_s @includes = [] @excludes = [] end |
Instance Method Details
#exclude(*files) ⇒ Object
250 251 252 253 |
# File 'lib/buildr/packaging/archive.rb', line 250 def exclude(*files) @excludes |= files self end |
#expand(file_map, path) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/buildr/packaging/archive.rb', line 255 def (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: <<
244 245 246 247 |
# File 'lib/buildr/packaging/archive.rb', line 244 def include(*files) @includes |= files self end |