module Shrine::Plugins::RemoteUrl::ClassMethods

Public Instance Methods

remote_url(url, **options) click to toggle source

Downloads the file using the “down” gem or a custom downloader. Checks the file size and terminates the download early if the file is too big.

# File lib/shrine/plugins/remote_url.rb, line 55
def remote_url(url, **options)
  options = { max_size: opts[:remote_url][:max_size] }.merge(options)

  instrument_remote_url(url, options) do
    download_remote_url(url, options)
  end
end

Private Instance Methods

download_remote_url(url, options) click to toggle source
# File lib/shrine/plugins/remote_url.rb, line 65
def download_remote_url(url, options)
  opts[:remote_url][:downloader].call(url, **options)
rescue Down::TooLarge
  fail DownloadError, "remote file too large"
rescue Down::Error
  fail DownloadError, "remote file not found"
rescue DownloadError
  fail # re-raise
end
instrument_remote_url(url, options) { || ... } click to toggle source

Sends a ‘remote_url.shrine` event for instrumentation plugin.

# File lib/shrine/plugins/remote_url.rb, line 76
def instrument_remote_url(url, options, &block)
  return yield unless respond_to?(:instrument)

  instrument(:remote_url, remote_url: url, download_options: options, &block)
end