Class: Shrine::Storage::Url
- Inherits:
-
Object
- Object
- Shrine::Storage::Url
- Defined in:
- lib/shrine/storage/url.rb
Instance Attribute Summary collapse
-
#downloader ⇒ Object
readonly
Returns the value of attribute downloader.
Instance Method Summary collapse
- #delete(id) ⇒ Object
- #exists?(id) ⇒ Boolean
-
#initialize(downloader: :http, delete: false) ⇒ Url
constructor
A new instance of Url.
- #open(id, **options) ⇒ Object
- #upload(io, id) ⇒ Object
- #url(id, **options) ⇒ Object
Constructor Details
#initialize(downloader: :http, delete: false) ⇒ Url
Returns a new instance of Url.
9 10 11 12 |
# File 'lib/shrine/storage/url.rb', line 9 def initialize(downloader: :http, delete: false) @downloader = resolve_downloader(downloader) @delete = delete end |
Instance Attribute Details
#downloader ⇒ Object (readonly)
Returns the value of attribute downloader.
7 8 9 |
# File 'lib/shrine/storage/url.rb', line 7 def downloader @downloader end |
Instance Method Details
#delete(id) ⇒ Object
33 34 35 |
# File 'lib/shrine/storage/url.rb', line 33 def delete(id) request(:delete, id) if @delete end |
#exists?(id) ⇒ Boolean
24 25 26 27 |
# File 'lib/shrine/storage/url.rb', line 24 def exists?(id) response = request(:head, id) response.status.success? end |
#open(id, **options) ⇒ Object
18 19 20 21 22 |
# File 'lib/shrine/storage/url.rb', line 18 def open(id, **) downloader.open(id, **) rescue Down::NotFound raise Shrine::FileNotFound, "file #{id.inspect} not found on storage" end |
#upload(io, id) ⇒ Object
14 15 16 |
# File 'lib/shrine/storage/url.rb', line 14 def upload(io, id, **) id.replace(io.url) end |
#url(id, **options) ⇒ Object
29 30 31 |
# File 'lib/shrine/storage/url.rb', line 29 def url(id, **) id end |