class Dragonfly::CloudinaryDatastore
Public Instance Methods
destroy(uid)
click to toggle source
# File lib/dragonfly/cloudinary_datastore.rb, line 17 def destroy(uid) Cloudinary::Uploader.destroy(uid) end
read(uid)
click to toggle source
# File lib/dragonfly/cloudinary_datastore.rb, line 12 def read(uid) resource = Cloudinary::Api.resource(File.basename(uid, File.extname(uid))) [Cloudinary::Downloader.download(uid), deserialize_to_hash(resource['tags'])] end
write(content, opts={})
click to toggle source
# File lib/dragonfly/cloudinary_datastore.rb, line 7 def write(content, opts={}) result = Cloudinary::Uploader.upload(content.path, { tags: serialize_hash(content.meta) }) "#{result['public_id']}.#{result['format']}" end
Private Instance Methods
deserialize_to_hash(str_arr)
click to toggle source
# File lib/dragonfly/cloudinary_datastore.rb, line 27 def deserialize_to_hash(str_arr) return str_arr if str_arr.nil? res = str_arr.map { |x| x.split("=>") }.flatten hash = Hash[*res.flatten] hash end
serialize_hash(hash)
click to toggle source
# File lib/dragonfly/cloudinary_datastore.rb, line 22 def serialize_hash(hash) return hash if hash.nil? hash.map { |k, v| "#{k}=>#{v}"} end