Class: Mandy::Packer

Inherits:
Object
  • Object
show all
Defined in:
lib/mandy/packer.rb

Constant Summary collapse

TMP_DIR =
'/tmp/mandy'
MANDY_DIR =
File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))

Class Method Summary collapse

Class Method Details

.cleanup!(file) ⇒ Object



24
25
26
27
# File 'lib/mandy/packer.rb', line 24

def self.cleanup!(file)
  return false unless File.extname(file) == '.tar'
  FileUtils.rm_r(File.dirname(file)) if File.exists?(File.dirname(file))
end

.pack(script, dir, gemfile = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mandy/packer.rb', line 8

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