Class: Chrysalis::Archive

Inherits:
Object show all
Defined in:
lib/chrysalis/archive.rb

Constant Summary collapse

@@archives =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Archive.



45
46
47
# File 'lib/chrysalis/archive.rb', line 45

def initialize(path, params = {})
  @path = path
end

Class Method Details

.extract(path, to = '.', params = {}) ⇒ Object

Extracts the archive, located at path, to the directory to (which defaults to the current directory). An optional set of parameters is accepted as params.

Returns the directory the archive was extracted into.

The return value assumes standard conventions are followed by the archive, namely that the directory is the name of the archive file, without the extension.

For example, given an archive file libfoo-1.4.2.tar.gz, the directory returned would be libfoo-1.4.2.

For archives that don’t follow this practice, parameters are available to override default behavior.

Raises:



29
30
31
32
33
34
35
36
37
38
# File 'lib/chrysalis/archive.rb', line 29

def self.extract(path, to = '.', params = {})
  pn = Pathname.new(path)
  return pn.cleanpath.to_s if pn.directory?
  return pn.cleanpath.to_s if params[:noop]
  
  @@archives.reverse.each { |archive|
    return archive.new(path, params).extract(to) if archive.extracts?(path)
  }
  raise ArchiveError, "Unknown archive format. (ext: #{pn.extname})"
end

.extracts?(path) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/chrysalis/archive.rb', line 41

def self.extracts?(path)
  false
end

.inherited(archive) ⇒ Object



10
11
12
# File 'lib/chrysalis/archive.rb', line 10

def self.inherited(archive)
  @@archives << archive
end

Instance Method Details

#extract(to = '.') ⇒ Object

Raises:



49
50
51
# File 'lib/chrysalis/archive.rb', line 49

def extract(to = '.')
  raise UnimplementedError, "Archive#extract not implemented"
end