Class: IMW::Tools::Downloader
- Inherits:
-
Object
- Object
- IMW::Tools::Downloader
- Defined in:
- lib/imw/tools/downloader.rb
Overview
A class to download a collection of resources to a shared directory.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
Class Method Summary collapse
Instance Method Summary collapse
- #after_download ⇒ Object
- #before_download ⇒ Object
- #clean! ⇒ Object
- #download! ⇒ Object
- #downloaded? ⇒ Boolean
- #downloaded_path_for(input) ⇒ Object
- #downloaded_resources ⇒ Object
-
#initialize(dir, *inputs) ⇒ Downloader
constructor
A new instance of Downloader.
Constructor Details
#initialize(dir, *inputs) ⇒ Downloader
Returns a new instance of Downloader.
8 9 10 11 |
# File 'lib/imw/tools/downloader.rb', line 8 def initialize dir, *inputs self.dir = dir self.inputs = inputs unless inputs.blank? end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
18 19 20 |
# File 'lib/imw/tools/downloader.rb', line 18 def dir @dir end |
#inputs ⇒ Object
Returns the value of attribute inputs.
23 24 25 |
# File 'lib/imw/tools/downloader.rb', line 23 def inputs @inputs end |
Class Method Details
Instance Method Details
#after_download ⇒ Object
57 58 |
# File 'lib/imw/tools/downloader.rb', line 57 def after_download end |
#before_download ⇒ Object
54 55 |
# File 'lib/imw/tools/downloader.rb', line 54 def before_download end |
#clean! ⇒ Object
49 50 51 52 |
# File 'lib/imw/tools/downloader.rb', line 49 def clean! IMW.log_if_verbose("Deleting downloader directory #{dir}") dir.rm_rf! end |
#download! ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/imw/tools/downloader.rb', line 29 def download! before_download inputs.each do |input| downloaded_path = downloaded_path_for(input) IMW.log_if_verbose "Downloading #{input} to #{downloaded_path}" input.cp(downloaded_path) end after_download end |
#downloaded? ⇒ Boolean
39 40 41 |
# File 'lib/imw/tools/downloader.rb', line 39 def downloaded? downloaded_resources.all? { |resource| resource.exist? } end |
#downloaded_path_for(input) ⇒ Object
25 26 27 |
# File 'lib/imw/tools/downloader.rb', line 25 def downloaded_path_for input dir.join(input.respond_to?(:effective_basename) ? input.effective_basename : input.basename) end |