class Workspace::Dir
Public Instance Methods
compress(target_file, &block)
click to toggle source
# File workspace-archive.rb, line 6 def compress(target_file, &block) target_file.delete if target_file.extension == "gz" compress_gz(target_file, &block) else compress_zip(target_file, &block) end self end
Private Instance Methods
compress_gz(target_file)
click to toggle source
# File workspace-archive.rb, line 18 def compress_gz(target_file) ::File.open(target_file.to_s, "wb") do |gzfile| Zlib::GzipWriter.wrap(gzfile) do |gz| Gem::Package::TarWriter.new(gz) do |tar| children("**/*") do |child| mode = ::File.stat(child.to_s).mode if child.kind_of?(File) tar.add_file_simple(child.relative_path, mode, child.read.length) do |io| io.write(child.read) end elsif child.kind_of?(Dir) tar.mkdir(child.relative_path, mode) end end end end end target_file end
compress_zip(target_file) { |path| ... }
click to toggle source
# File workspace-archive.rb, line 38 def compress_zip(target_file, &block) Zip::File.open(target_file.to_s, 'w') do |zipfile| ::Dir.glob("#{self}/**/**", ::File::FNM_DOTMATCH).each do |file| path = file.sub("#{self}/", '') zipfile.add(path, file) unless block_given? and !yield(path) end end end