class Traquitana::Packager
Attributes
id[R]
verbose[RW]
Public Class Methods
new(dir = '')
click to toggle source
# File lib/packager.rb, line 9 def initialize(dir = '') @dir = dir @id = Time.now.strftime('%Y%m%d%H%M%S%L') @verbose = verbose end
Public Instance Methods
list_file()
click to toggle source
# File lib/packager.rb, line 15 def list_file "#{@id}.list" end
pack()
click to toggle source
# File lib/packager.rb, line 23 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
zip_file()
click to toggle source
# File lib/packager.rb, line 19 def zip_file "#{@id}.zip" end