Class: Chrysalis::Ar::TarArchive

Inherits:
Chrysalis::Archive show all
Defined in:
lib/chrysalis/ar/tar.rb

Overview

Implements support for extracting tar archives.

Archives of this type are identified by the file extension tar.

Direct Known Subclasses

TarBz2Archive, TarGzArchive

Constant Summary collapse

EXTENSION =
".tar".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chrysalis::Archive

extract, inherited

Constructor Details

#initialize(path, params = {}) ⇒ TarArchive

Returns a new instance of TarArchive.



19
20
21
22
23
24
# File 'lib/chrysalis/ar/tar.rb', line 19

def initialize(path, params = {})
  super
  @extract_to = params[:extract_to]
  @extracts_into = params[:extracts_into]
  @noop = params[:noop]
end

Class Method Details

.extracts?(path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/chrysalis/ar/tar.rb', line 15

def self.extracts?(path)
  path.end? EXTENSION
end

Instance Method Details

#extract(to = '.') ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chrysalis/ar/tar.rb', line 26

def extract(to = '.')
  dir = Pathname.new(to)
  dir = dir + @extract_to if @extract_to
  
  unless @noop
    FileUtils.mkpath dir
    
    bin = (RUBY_PLATFORM.match(/mswin/) ? "bsdtar" : "tar")
  
    puts "Extracting #{@path} ..."
    sh "#{bin} #{self.flags} #{@path} -C #{dir.cleanpath}"
  end
  
  ex_path = Pathname.new(dir).join(self.extracts_into)
  ex_path.cleanpath.to_s
end