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

Instance Method Details

#exist?URI, FalseClass

Returns:

  • (URI)

    when the URL resolves successfully

  • (FalseClass)

    when the URL’s head request is not successful or we’ve exhausted our remaining redirects.



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.message}\n#{e.backtrace.join("\n")}))
  false
end

#get(url) ⇒ String

Parameters:

  • url (String)

Returns:

  • (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.message}\n#{e.backtrace.join("\n")}))
  raise e
end

#matching_locations_in_file_dir(tail_regexp:) ⇒ Array

Returns always returns an empty array.

Parameters:

  • tail_regexp (Regex)

    the file pattern that we’re looking to find; but due to the nature of this location adapter, it won’t matter.

Returns:

  • (Array)

    always returns an empty array.

See Also:



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

#writeObject

Implemented to complete the interface.

Raises:

  • (NotImplementedError)


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