Module: Shrine::Plugins::RemoteUrl::AttacherMethods
- Defined in:
- lib/shrine/plugins/remote_url.rb
Instance Method Summary collapse
-
#assign_remote_url(url, downloader: {}, **options) ⇒ Object
Downloads the remote file and assigns it.
-
#remote_url ⇒ Object
Form builders require the reader as well.
-
#remote_url=(url) ⇒ Object
Alias for #assign_remote_url.
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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/shrine/plugins/remote_url.rb', line 73 def assign_remote_url(url, downloader: {}, **) return if url == "" || url.nil? begin downloaded_file = shrine_class.remote_url(url, downloader) rescue => error download_error = error end if downloaded_file assign(downloaded_file, **) else = (url, download_error) errors.replace [] @remote_url = url end end |
#remote_url ⇒ Object
Form builders require the reader as well.
97 98 99 |
# File 'lib/shrine/plugins/remote_url.rb', line 97 def remote_url @remote_url end |
#remote_url=(url) ⇒ Object
Alias for #assign_remote_url.
92 93 94 |
# File 'lib/shrine/plugins/remote_url.rb', line 92 def remote_url=(url) assign_remote_url(url) end |