lib/packer.rb in mandy-0.2.15 vs lib/packer.rb in mandy-0.3.1

- old
+ new

@@ -2,15 +2,18 @@ module Mandy class Packer TMP_DIR = '/tmp/mandy' - def self.pack(dir) - return dir if File.file?(dir) - FileUtils.mkdir_p(TMP_DIR) - tmp_path = "#{TMP_DIR}/packed-job-#{Time.now.to_i}.tar" - Dir.chdir(dir) { `tar -cf #{tmp_path} *` } - tmp_path + def self.pack(dir, gemfile) + tmp_path = "#{TMP_DIR}/packed-job-#{Time.now.to_i}" + FileUtils.mkdir_p(tmp_path) + to_be_copied = File.file?(dir) ? dir : File.join(dir, '*') + FileUtils.cp_r(Dir.glob(to_be_copied), tmp_path) + FileUtils.cp_r(gemfile, tmp_path) + Dir.chdir(tmp_path) { `gem bundle` } + Dir.chdir(tmp_path) { `tar -cf bundle.tar *` } + File.join(tmp_path, 'bundle.tar') end def self.unpack(file) return false unless File.extname(file) == '.tar' `tar -xf #{file}` \ No newline at end of file