Module: Gonzui::Fetcher

Extended by:
Util
Defined in:
lib/gonzui/fetcher.rb

Constant Summary collapse

FetcherRegistory =
{}

Class Method Summary collapse

Methods included from Util

assert, assert_equal, assert_equal_all, assert_non_nil, assert_not_reached, benchmark, command_exist?, commify, eprintf, format_bytes, program_name, protect_from_signals, require_command, set_verbosity, shell_escape, unix?, vprintf, windows?, wprintf

Class Method Details

.new(config, source_uri, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gonzui/fetcher.rb', line 25

def new(config, source_uri, options = {})
  klass = FetcherRegistory[source_uri.scheme]
  if klass.nil?
    raise FetcherError.new("#{source_uri.scheme}: unsupported scheme")
  end
  if source_uri.path.nil?
    raise FetcherError.new("#{source_uri.to_s}: malformed URI")
  end
  fetcher = klass.new(config, source_uri, options)
  if fetcher.need_extraction? # fallback to FileFetcher
    extractor = fetcher.get_extractor
    directory = extractor.extract
    fetcher.finish

    source_uri = URI.from_path(directory)
    fetcher = FileFetcher.new(config, source_uri, options)
    fetcher.add_finishing_proc(lambda { extractor.clean })
  end
  return fetcher
end

.register(klass) ⇒ Object



46
47
48
# File 'lib/gonzui/fetcher.rb', line 46

def register(klass)
  FetcherRegistory[klass.scheme] = klass
end