Sha256: 60bf8ffb08ac6eb8718b8909b9753778085833782f1311f77beca528a0ad02a0
Contents?: true
Size: 1.1 KB
Versions: 14
Compression:
Stored size: 1.1 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') do |file| file << list.map do |f| f.sub(regex, '') end.join("\n") end # 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
14 entries across 14 versions & 1 rubygems