Class: Nucleus::ArchiveExtractor
- Inherits:
-
Object
- Object
- Nucleus::ArchiveExtractor
- Defined in:
- lib/nucleus/core/common/files/archive_extractor.rb
Instance Method Summary collapse
-
#extract(file, destination_path, compression_format) ⇒ Integer
Extract the file to the destination path.
-
#initialize(exclude_git = true) ⇒ ArchiveExtractor
constructor
A new instance of ArchiveExtractor.
-
#supports?(compression_format) ⇒ Boolean
Checks if the compression format is supported and an archive of this type could be extracted.
Constructor Details
#initialize(exclude_git = true) ⇒ ArchiveExtractor
Returns a new instance of ArchiveExtractor.
3 4 5 |
# File 'lib/nucleus/core/common/files/archive_extractor.rb', line 3 def initialize(exclude_git = true) @exclude_git = exclude_git end |
Instance Method Details
#extract(file, destination_path, compression_format) ⇒ Integer
Extract the file to the destination path. The compression format indicates which method must be used to extract the archive.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/nucleus/core/common/files/archive_extractor.rb', line 14 def extract(file, destination_path, compression_format) compression_method = compression_format_method_name(compression_format) fail StandardError, 'Unsupported compression format' unless respond_to?(compression_method, true) # be sure that directory exists FileUtils.mkdir_p(destination_path, verbose: false) begin send(compression_method, file, destination_path) rescue Zip::Error, Zlib::GzipFile::Error raise API::Errors::ApplicationArchiveError, "Failed to extract #{compression_format} archive" end end |
#supports?(compression_format) ⇒ Boolean
Checks if the compression format is supported and an archive of this type could be extracted.
31 32 33 34 |
# File 'lib/nucleus/core/common/files/archive_extractor.rb', line 31 def supports?(compression_format) compression_method = compression_format_method_name(compression_format) respond_to?(compression_method, true) end |