Class: Shrine::Storage::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/storage/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#downloaderObject (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

Returns:

  • (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, **options)
  downloader.open(id, **options)
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, **options)
  id
end