Module: Suvii

Defined in:
lib/suvii.rb,
lib/suvii/http.rb,
lib/suvii/cache.rb,
lib/suvii/extract.rb,
lib/suvii/extract/zip.rb,
lib/suvii/extract/targz.rb

Overview

Since:

  • 0.1.0

Defined Under Namespace

Classes: Cache, Extract, Http

Class Method Summary collapse

Class Method Details

.fetch(url, options = {}) ⇒ String

Downloads and extracts an archive to a temp directory.

Parameters:

  • url (String)

    URL of an archive to be fetched.

Options Hash (options):

  • :cache_path (String) — default: random temporary directory

    where the downloaded archive should be stored. You can provide path to a persistent folder to prevent downloading same files again.

  • :max_attempts_for_200_response (Integer) — default: 1, i.e. no retries

    number of times to fetch a remote resource until get a 200 response.

  • :strip_components (Integer) — default: 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.

Returns:

  • (String)

    path to a temp directory with the archive being extracted.

Since:

  • 0.1.0



17
18
19
20
21
22
23
24
# File 'lib/suvii.rb', line 17

def self.fetch(url, options = {})
  path_to_archive = Cache.fetch(url, options) do |path|
    Http.save(url, path, options)
  end

  extractor = Extract.class_for(path_to_archive).new(path_to_archive, options)
  extractor.extract_to(Dir.mktmpdir)
end

.loggerLogger

Returns instance of Logger compatible class.

Returns:

  • (Logger)

    instance of Logger compatible class.

Since:

  • 0.1.0



27
28
29
30
31
32
# File 'lib/suvii.rb', line 27

def self.logger
  @logger ||= Logger.new(STDOUT).tap do |logger|
    logger.level = Logger::INFO
    logger.formatter = proc { |_, _, _, msg| msg }
  end
end

.logger=(logger) ⇒ Object

Overrides default logger instance.

Parameters:

  • logger (Logger)

    instance of Logger compatible class.

Since:

  • 0.1.0



37
38
39
# File 'lib/suvii.rb', line 37

def self.logger=(logger)
  @logger = logger
end