Sha256: d5e3bbed7bfb1e6e7c99dab298e572f31207a2914f4d499aa7cdf72599b053e0
Contents?: true
Size: 1.15 KB
Versions: 6
Compression:
Stored size: 1.15 KB
Contents
require "tmpdir" require "zip/zip" module Traquitana class Packager attr_reader :id attr_accessor :verbose def initialize(dir="") @dir = dir @id = Time.now.strftime("%Y%m%d%H%M%S%L") @verbose = verbose end def list_file "#{@id}.list" end def zip_file "#{@id}.zip" end def pack list_path = "#{Dir.tmpdir}/#{self.list_file}" zip_path = "#{Dir.tmpdir}/#{self.zip_file}" list = Traquitana::Selector.new(@dir).files regex = @dir.to_s.size<1 ? "" : Regexp.new("^#{@dir}") # write list file STDOUT.puts "Creating the list file: #{list_path}" if @verbose File.open(list_path,"w") {|file| file << list.map {|f| f.sub(regex,"")}.join("\n") } # write zip file STDOUT.puts "Creating the zip file : #{zip_path}" if @verbose Zip::ZipFile.open(zip_path ,"w") do |zip_file| for file in list strip = file.sub(regex,"") zip_file.add(strip,file) end end [list_path,zip_path] end end end
Version data entries
6 entries across 6 versions & 1 rubygems