Module: PEBuild::Transfer::OpenURI Private
- Extended by:
- Idempotent
- Defined in:
- lib/pe_build/transfer/open_uri.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: DownloadFailed
Constant Summary collapse
- HEADERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{'User-Agent' => "Vagrant/PEBuild (v#{PEBuild::VERSION})"}
Class Method Summary collapse
- .copy(uri, dst) ⇒ Object private
-
.download_file(uri) ⇒ IO
private
Open a open-uri file handle for the given URL.
-
.read(uri) ⇒ String
private
The contents of the file with leading and trailing whitespace removed.
Methods included from Idempotent
Class Method Details
.copy(uri, dst) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 23 24 25 26 |
# File 'lib/pe_build/transfer/open_uri.rb', line 19 def self.copy(uri, dst) idempotent(dst) do tmpfile = download_file(uri) FileUtils.mv(tmpfile, dst) end rescue StandardError => e raise DownloadFailed, :uri => uri, :msg => e. end |
.download_file(uri) ⇒ IO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Open a open-uri file handle for the given URL
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pe_build/transfer/open_uri.rb', line 43 def self.download_file(uri) progress = nil content_length_proc = lambda do |length| if length and length > 0 STDERR.puts "Fetching: #{uri}" progress = ProgressBar.new("Fetching file", length, STDERR) progress.file_transfer_mode end end progress_proc = lambda do |size| progress.set(size) if progress end = HEADERS.merge({ :content_length_proc => content_length_proc, :progress_proc => progress_proc, }) uri.open() end |
.read(uri) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The contents of the file with leading and trailing whitespace removed.
33 34 35 36 37 |
# File 'lib/pe_build/transfer/open_uri.rb', line 33 def self.read(uri) uri.read(HEADERS.merge({'Accept' => 'text/plain'})).strip rescue StandardError => e raise DownloadFailed, :uri => uri, :msg => e. end |