Sha256: f3be65f9244e3a0271c605e4e78f739cd15af663976a33027aa0aa3a2b257b9c

Contents?: true

Size: 941 Bytes

Versions: 1

Compression:

Stored size: 941 Bytes

Contents

require "fileutils"

module Mandy
  class Packer
    TMP_DIR = '/tmp/mandy'
    MANDY_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
    
    def self.pack(script, dir, gemfile=nil)
      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(script, tmp_path)
      FileUtils.cp(File.join(MANDY_DIR, 'VERSION'), tmp_path)
      FileUtils.cp_r(Dir.glob(to_be_copied), tmp_path)
      if gemfile and File.exists?(gemfile)
        FileUtils.cp(gemfile, File.join(tmp_path, 'geminstaller.yml')) 
      else
        FileUtils.cp(File.join(MANDY_DIR, 'geminstaller.yml'), tmp_path)
      end
      Dir.chdir(tmp_path) { `tar -cf bundle.tar *` }
      File.join(tmp_path, 'bundle.tar')
    end
    
    def self.cleanup!(file)
      tmp_dir = File.dirname(file)
      FileUtils.rm_r(tmp_dir)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mandy-0.5.3 lib/mandy/packer.rb