Sha256: 70198df7710144405c9273918becbeea7c9ece185cd6ddd02aa7c8c94ca77453
Contents?: true
Size: 1.14 KB
Versions: 9
Compression:
Stored size: 1.14 KB
Contents
require "tmpdir" require "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::File.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
9 entries across 9 versions & 1 rubygems