Class: Nucleus::Archiver

Inherits:
Object
  • Object
show all
Defined in:
lib/nucleus/core/common/files/archiver.rb

Instance Method Summary collapse

Constructor Details

#initialize(exclude_git = true) ⇒ Archiver

Returns a new instance of Archiver.



3
4
5
# File 'lib/nucleus/core/common/files/archiver.rb', line 3

def initialize(exclude_git = true)
  @exclude_git = exclude_git
end

Instance Method Details

#compress(path, compression_format) ⇒ StringIO

Compress the files of the path into an archive, using the compression format, which indicates which method must be used to compress the archive.

Parameters:

  • path (String)

    which directory’s contents are going to be compressed into the archive

  • compression_format (String)

    represented by well-known file extensions, e.g. zip or tar.gz

Returns:

  • (StringIO)

    compressed data of the given input path

Raises:

  • (StandardError)

    if the compression_format is not supported and the directory can’t be compressed



13
14
15
16
17
18
# File 'lib/nucleus/core/common/files/archiver.rb', line 13

def compress(path, compression_format)
  compression_method = compression_format.downcase.gsub(/\./, '_').underscore.to_sym
  fail StandardError,
       "Unsupported compression format #{compression_format}" unless self.respond_to?(compression_method, true)
  send(compression_method, path)
end