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     = false
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


35
36
37
# File 'lib/shrine/storage/url.rb', line 35

def delete(id)
  request(:delete, id) if @delete
end

#download(id, **options) ⇒ Object


18
19
20
# File 'lib/shrine/storage/url.rb', line 18

def download(id, **options)
  @downloader.download(id, **options)
end

#exists?(id) ⇒ Boolean

Returns:

  • (Boolean)

26
27
28
29
# File 'lib/shrine/storage/url.rb', line 26

def exists?(id)
  response = request(:head, id)
  response.status.success?
end

#open(id, **options) ⇒ Object


22
23
24
# File 'lib/shrine/storage/url.rb', line 22

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


31
32
33
# File 'lib/shrine/storage/url.rb', line 31

def url(id, **options)
  id
end