Class: Tenderloin::Actions::Box::Download
- Inherits:
-
Tenderloin::Actions::Base
- Object
- Tenderloin::Actions::Base
- Tenderloin::Actions::Box::Download
- Defined in:
- lib/tenderloin/actions/box/download.rb
Overview
An action which acts on a box by downloading the box file from the given URI into a temporary location. This action parses a given URI and handles downloading it via one of the many Tenderloin downloads (such as Downloaders::File).
This action cleans itself up by removing the downloaded box file.
Constant Summary collapse
- BASENAME =
"box"
- BUFFERSIZE =
1 MB
1048576
Instance Attribute Summary collapse
-
#downloader ⇒ Object
readonly
Returns the value of attribute downloader.
Attributes inherited from Tenderloin::Actions::Base
Instance Method Summary collapse
- #cleanup ⇒ Object
- #download_to(f) ⇒ Object
- #execute! ⇒ Object
- #prepare ⇒ Object
- #rescue(exception) ⇒ Object
- #with_tempfile ⇒ Object
Methods inherited from Tenderloin::Actions::Base
Methods included from Util
#error_and_exit, included, #logger, #wrap_output
Constructor Details
This class inherits a constructor from Tenderloin::Actions::Base
Instance Attribute Details
#downloader ⇒ Object (readonly)
Returns the value of attribute downloader.
14 15 16 |
# File 'lib/tenderloin/actions/box/download.rb', line 14 def downloader @downloader end |
Instance Method Details
#cleanup ⇒ Object
38 39 40 41 42 43 |
# File 'lib/tenderloin/actions/box/download.rb', line 38 def cleanup if @runner.temp_path && File.exist?(@runner.temp_path) logger.info "Cleaning up downloaded box..." File.unlink(@runner.temp_path) end end |
#download_to(f) ⇒ Object
56 57 58 59 |
# File 'lib/tenderloin/actions/box/download.rb', line 56 def download_to(f) logger.info "Copying box to temporary location..." downloader.download!(@runner.uri, f) end |
#execute! ⇒ Object
31 32 33 34 35 36 |
# File 'lib/tenderloin/actions/box/download.rb', line 31 def execute! with_tempfile do |tempfile| download_to(tempfile) @runner.temp_path = tempfile.path end end |
#prepare ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tenderloin/actions/box/download.rb', line 16 def prepare # Parse the URI given and prepare a downloader uri = URI.parse(@runner.uri) uri_map = [[URI::HTTP, Downloaders::HTTP], [URI::Generic, Downloaders::File]] uri_map.find do |uri_type, downloader_klass| if uri.is_a?(uri_type) logger.info "#{uri_type} for URI, downloading via #{downloader_klass}..." @downloader = downloader_klass.new end end raise ActionException.new("Unknown URI type for box download.") unless @downloader end |
#rescue(exception) ⇒ Object
45 46 47 |
# File 'lib/tenderloin/actions/box/download.rb', line 45 def rescue(exception) cleanup end |