Class: DepsGrapher::Visualizer::Downloader
- Inherits:
-
Object
- Object
- DepsGrapher::Visualizer::Downloader
- Includes:
- Logging
- Defined in:
- lib/deps_grapher/visualizer/downloader.rb
Instance Method Summary collapse
- #download(url, force: false) ⇒ Object
-
#initialize(download_dir) ⇒ Downloader
constructor
A new instance of Downloader.
Methods included from Logging
#error, #info, #verbose, #warn
Constructor Details
#initialize(download_dir) ⇒ Downloader
Returns a new instance of Downloader.
8 9 10 |
# File 'lib/deps_grapher/visualizer/downloader.rb', line 8 def initialize(download_dir) @download_dir = download_dir end |
Instance Method Details
#download(url, force: false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/deps_grapher/visualizer/downloader.rb', line 12 def download(url, force: false) uri = URI.parse url file_name = File.basename uri.to_s file_path = File.join @download_dir, file_name FileUtils.rm_f file_path if force return if File.exist?(file_path) response = get_response uri raise "download error occurred: #{uri} (#{response.code})" if response.code.to_i != 200 File.write file_path, response.body end |