Sha256: 71526af2774e7d88824f979784ce5907d64d5963fbfbfa90ef298359fdf4af55

Contents?: true

Size: 1.46 KB

Versions: 20

Compression:

Stored size: 1.46 KB

Contents

require 'vagrant-vbguest/download'
module VagrantVbguest
  # 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 - https://github.com/mitchellh/vagrant
  #
  #
  #
  class Download < DownloadBase

    include Vagrant::Util

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

    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

  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
vagrant-vbguest-0.16.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.16.0.beta1 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.15.2 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.15.1 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.15.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.14.2 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.14.1 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.14.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.14.0.pre.beta1 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.13.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.12.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.11.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.11.0.beta0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.10.1 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-update-0.10.1.dev lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.10.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.10.0.pre1 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.10.0.pre0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.9.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb
vagrant-vbguest-0.8.0 lib/vagrant-vbguest/vagrant_compat/vagrant_1_0/download.rb