Module: Shrine::Plugins::RemoteUrl::AttacherMethods

Defined in:
lib/shrine/plugins/remote_url.rb

Instance Method Summary collapse

Instance Method Details

#assign_remote_url(url, downloader: {}, **options) ⇒ Object

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.


87
88
89
90
91
92
93
94
95
# 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_urlObject

Used by `<name>_data_uri` attachment method.


104
105
106
# File 'lib/shrine/plugins/remote_url.rb', line 104

def remote_url
  @remote_url
end

#remote_url=(url) ⇒ Object

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


98
99
100
101
# File 'lib/shrine/plugins/remote_url.rb', line 98

def remote_url=(url)
  assign_remote_url(url)
  @remote_url = url
end