Module: DerivativeRodeo::StorageLocations::DownloadConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- HttpLocation, HttpsLocation
- Defined in:
- lib/derivative_rodeo/storage_locations/concerns/download_concern.rb
Overview
A helper module for copying files from one location to another.
Instance Method Summary collapse
- #exist? ⇒ URI, FalseClass
- #get(url) ⇒ String
-
#matching_locations_in_file_dir(tail_regexp:) ⇒ Array
Always returns an empty array.
- #with_existing_tmp_path(&block) ⇒ Object
-
#write ⇒ Object
Implemented to complete the interface.
Instance Method Details
#exist? ⇒ URI, FalseClass
57 58 59 60 61 62 |
# File 'lib/derivative_rodeo/storage_locations/concerns/download_concern.rb', line 57 def exist? HTTParty.head(file_uri, logger: logger) rescue => e logger.error(%(#{e.}\n#{e.backtrace.join("\n")})) false end |
#get(url) ⇒ String
46 47 48 49 50 51 |
# File 'lib/derivative_rodeo/storage_locations/concerns/download_concern.rb', line 46 def get(url) HTTParty.get(url, logger: logger) rescue => e logger.error(%(#{e.}\n#{e.backtrace.join("\n")})) raise e end |
#matching_locations_in_file_dir(tail_regexp:) ⇒ Array
Returns always returns an empty array.
71 72 73 74 75 |
# File 'lib/derivative_rodeo/storage_locations/concerns/download_concern.rb', line 71 def matching_locations_in_file_dir(tail_regexp:) logger.info("#{self.class}##{__method__} for file_uri: #{file_uri.inspect}, tail_regexp: #{tail_regexp} will always return an empty array. This is the nature of the #{self.class} location.") [] end |
#with_existing_tmp_path(&block) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/derivative_rodeo/storage_locations/concerns/download_concern.rb', line 25 def with_existing_tmp_path(&block) with_tmp_path(lambda { |file_path, tmp_file_path, exist| raise Errors::FileMissingError.with_info(method: __method__, context: self, file_path: file_path, tmp_file_path: tmp_file_path) unless exist response = get(file_uri) File.open(tmp_file_path, 'wb') { |fp| fp.write(response.body) } }, &block) end |
#write ⇒ Object
Implemented to complete the interface.
38 39 40 |
# File 'lib/derivative_rodeo/storage_locations/concerns/download_concern.rb', line 38 def write raise "#{self.class}#write is deliberately not implemented" end |