Class: PEBuild::Transfer::OpenURI

Inherits:
Object
  • Object
show all
Includes:
Idempotent
Defined in:
lib/pe_build/transfer/open_uri.rb

Defined Under Namespace

Classes: DownloadFailed

Constant Summary collapse

HEADERS =
{'User-Agent' => "Vagrant/PEBuild (v#{PEBuild::VERSION})"}

Instance Method Summary collapse

Methods included from Idempotent

#idempotent

Constructor Details

#initialize(uri, dst) ⇒ OpenURI

Returns a new instance of OpenURI.

Parameters:

  • uri (URI)

    The http(s) URI to the file to copy

  • dst (String)

    The path to destination of the copied file



15
16
17
18
19
# File 'lib/pe_build/transfer/open_uri.rb', line 15

def initialize(uri, dst)
  @uri, @dst = uri, dst

  @logger = Log4r::Logger.new('vagrant::pe_build::transfer::open_uri')
end

Instance Method Details

#copyObject



23
24
25
26
27
28
29
30
# File 'lib/pe_build/transfer/open_uri.rb', line 23

def copy
  idempotent(@dst) do
    tmpfile = download_file
    FileUtils.mv(tmpfile, @dst)
  end
rescue StandardError => e
  raise DownloadFailed, :uri => @uri, :msg => e.message
end