Class: VagrantVbguest::Download

Inherits:
DownloadBase show all
Includes:
Vagrant::Util
Defined in:
lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb,
lib/vagrant-vbguest/vagrant_compat/vagrant_1_2/download.rb

Overview

This implementation is based on Action::Box::Download by vagrant

This adoption does not run as a action/middleware, but is called manually

MIT License - Mitchell Hashimoto and John Bender - github.com/mitchellh/vagrant

Instance Attribute Summary

Attributes inherited from DownloadBase

#destination, #downloader, #source

Instance Method Summary collapse

Methods inherited from DownloadBase

#cleanup, #initialize

Constructor Details

This class inherits a constructor from VagrantVbguest::DownloadBase

Instance Method Details

#download!Object



15
16
17
18
19
20
21
22
# File 'lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb', line 15

def download!
  if instantiate_downloader
    File.open(@destination, Platform.tar_file_options) do |destination_file|
      @downloader.download!(@source, destination_file)
    end
  end
  @destination
end

#instantiate_downloaderObject

Raises:

  • (Errors::BoxDownloadUnknownType)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb', line 24

def instantiate_downloader
  # Assign to a temporary variable since this is easier to type out,
  # since it is used so many times.
  classes = [Vagrant::Downloaders::HTTP, Vagrant::Downloaders::File]

  # Find the class to use.
  classes.each_index do |i|
    klass = classes[i]

    # Use the class if it matches the given URI or if this
    # is the last class...
    if classes.length == (i + 1) || klass.match?(@source)
      @ui.info I18n.t("vagrant_vbguest.download.with", :class => klass.to_s)
      @downloader = klass.new(@ui)
      break
    end
  end

  # This line should never be reached, but we'll keep this here
  # just in case for now.
  raise Errors::BoxDownloadUnknownType if !@downloader

  @downloader.prepare(@source) if @downloader.respond_to?(:prepare)
  true
end