Class: Tenderloin::Actions::Box::Unpackage

Inherits:
Tenderloin::Actions::Base show all
Defined in:
lib/tenderloin/actions/box/unpackage.rb

Overview

This action unpackages a downloaded box file into its final box destination within the tenderloin home folder.

Instance Attribute Summary

Attributes inherited from Tenderloin::Actions::Base

#runner

Instance Method Summary collapse

Methods inherited from Tenderloin::Actions::Base

#cleanup, #initialize, #prepare

Methods included from Util

#error_and_exit, included, #logger, #wrap_output

Constructor Details

This class inherits a constructor from Tenderloin::Actions::Base

Instance Method Details

#box_dirObject



33
34
35
# File 'lib/tenderloin/actions/box/unpackage.rb', line 33

def box_dir
  @runner.directory
end

#decompressObject



37
38
39
40
41
42
# File 'lib/tenderloin/actions/box/unpackage.rb', line 37

def decompress
  Dir.chdir(box_dir) do
    logger.info "Extracting box to #{box_dir}..."
    Archive::Tar::Minitar.unpack(@runner.temp_path, box_dir)
  end
end

#execute!Object



8
9
10
11
12
13
# File 'lib/tenderloin/actions/box/unpackage.rb', line 8

def execute!
  @runner.invoke_around_callback(:unpackage) do
    setup_box_dir
    decompress
  end
end

#rescue(exception) ⇒ Object



15
16
17
18
19
20
# File 'lib/tenderloin/actions/box/unpackage.rb', line 15

def rescue(exception)
  if File.directory?(box_dir)
    logger.info "An error occurred, rolling back box unpackaging..."
    FileUtils.rm_rf(box_dir)
  end
end

#setup_box_dirObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/tenderloin/actions/box/unpackage.rb', line 22

def setup_box_dir
  if File.directory?(box_dir)
    error_and_exit(<<-msg)
This box appears to already exist! Please call `tenderloin box remove #{@runner.name}`
and then try to add it again.
msg
  end

  FileUtils.mkdir_p(box_dir)
end