Class: Buildr::ZipTask::ZipExpander

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

Instance Method Summary collapse

Constructor Details

#initialize(zip_file) ⇒ ZipExpander

Returns a new instance of ZipExpander.



161
162
163
# File 'lib/tasks/zip.rb', line 161

def initialize(zip_file)
  @zip_file = zip_file.to_s
end

Instance Method Details

#exclude(*files) ⇒ Object



171
172
173
174
175
# File 'lib/tasks/zip.rb', line 171

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

#expand(zip, path) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/tasks/zip.rb', line 177

def expand(zip, path)
  @includes ||= ["*"]
  @excludes ||= []
  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) }
        puts "Adding #{path}#{entry.name}" if Rake.application.options.trace
        zip.get_output_stream("#{path}#{entry.name}") { |output| output.write source.read(entry) }
        # TODO: read and write file
      end
    end
  end
end

#include(*files) ⇒ Object



165
166
167
168
169
# File 'lib/tasks/zip.rb', line 165

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