class Suvii::Extract
Constants
- TARGZ_RE
- UnknownFormatError
- ZIP_RE
Attributes
source[R]
@return [String]
strip_components[R]
@return [Integer, nil]
Public Class Methods
class_for(source)
click to toggle source
Detects proper class for given archive path.
@return [Targz, Zip] @param source [String] local path to an archive. @raise [UnknownFormatError] when archive format is not supported.
# File lib/suvii/extract.rb, line 13 def self.class_for(source) case source when TARGZ_RE then Targz when ZIP_RE then Zip else raise UnknownFormatError, "unknown format for #{source}" end end
new(source, options = {})
click to toggle source
@param source [String] local path to an archive. @option options [Integer] :strip_components (nil, i.e. no skipping) specifies number of top-level
directories to be skipped during the archive extraction. Same as `strip-components` option for GNU tar.
# File lib/suvii/extract.rb, line 31 def initialize(source, options = {}) @source = source @strip_components = options[:strip_components] end
Public Instance Methods
extract_to(destination)
click to toggle source
Performs archive extraction.
@param destination [String] directory where the archive should be extracted. @return [String] destination.
# File lib/suvii/extract.rb, line 40 def extract_to(destination) raise NotImplementedError end
Private Instance Methods
path_with_stripped_components(path)
click to toggle source
# File lib/suvii/extract.rb, line 46 def path_with_stripped_components(path) if strip_components segments = path.split(File::SEPARATOR) segments[strip_components..-1].join(File::SEPARATOR) else path end end