Class: Dragonfly::DataStorage::CloudinaryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly/data_storage/cloudinary_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ CloudinaryStore

Returns a new instance of CloudinaryStore.



6
7
# File 'lib/dragonfly/data_storage/cloudinary_store.rb', line 6

def initialize config={}
end

Instance Method Details

#destroy(uid) ⇒ Object



19
20
21
# File 'lib/dragonfly/data_storage/cloudinary_store.rb', line 19

def destroy(uid)
  ::Cloudinary::Uploader.destroy public_id(uid)
end

#retrieve(uid) ⇒ Object



14
15
16
17
# File 'lib/dragonfly/data_storage/cloudinary_store.rb', line 14

def retrieve(uid)
  url = ::Cloudinary::Utils.cloudinary_url public_id(uid), format: ext(uid) || 'jpg'
  ::Cloudinary::Downloader.download(url)
end

#store(temp_object, opts = {}) ⇒ Object



9
10
11
12
# File 'lib/dragonfly/data_storage/cloudinary_store.rb', line 9

def store(temp_object, opts={})
  result = ::Cloudinary::Uploader.upload(temp_object.path)
  result['public_id'] + "." + result['format']
end

#url_for(uid, options = {}) ⇒ Object



23
24
25
26
# File 'lib/dragonfly/data_storage/cloudinary_store.rb', line 23

def url_for(uid, options = {})
  options = {format: ext(uid)}.merge(options)
  ::Cloudinary::Utils.cloudinary_url(public_id(uid), options)
end