module Shrine::Plugins::RemoteUrl::AttacherMethods

Public Instance Methods

assign_remote_url(url, downloader: {}, **options) click to toggle source

Downloads the remote file and assigns it. If download failed, sets the error message and assigns the url to an instance variable so that it shows up in the form.

# File lib/shrine/plugins/remote_url.rb, line 87
def assign_remote_url(url, downloader: {}, **options)
  return if url == "" || url.nil?

  downloaded_file = shrine_class.remote_url(url, **downloader)
  attach_cached(downloaded_file, **options)
rescue DownloadError => error
  errors.clear << remote_url_error_message(url, error)
  false
end
remote_url() click to toggle source

Used by ‘<name>_data_uri` attachment method.

# File lib/shrine/plugins/remote_url.rb, line 104
def remote_url
  @remote_url
end
remote_url=(url) click to toggle source

Used by ‘<name>_data_uri=` attachment method.

# File lib/shrine/plugins/remote_url.rb, line 98
def remote_url=(url)
  assign_remote_url(url)
  @remote_url = url
end

Private Instance Methods

remote_url_error_message(url, error) click to toggle source

Generates an error message for failed remote URL download.

# File lib/shrine/plugins/remote_url.rb, line 111
def remote_url_error_message(url, error)
  message = shrine_class.opts[:remote_url][:error_message]
  message = message.call *[url, error].take(message.arity.abs) if message.respond_to?(:call)
  message || "download failed: #{error.message}"
end