class Dragonfly::MongoidDataStore

Constants

OBJECT_ID
VERSION

Public Instance Methods

destroy(uid) click to toggle source
# File lib/dragonfly/mongoid_data_store.rb, line 39
def destroy(uid)
  Mongoid::GridFs.delete(uid)
end
read(uid) click to toggle source
# File lib/dragonfly/mongoid_data_store.rb, line 26
def read(uid)
  grid_file = Mongoid::GridFS.get(uid)

  meta = {}
  meta = marshal_b64_decode(grid_file.meta) if grid_file.respond_to?(:meta)
  meta[:stored_at] = grid_file.upload_date if grid_file.respond_to?(:upload_date)

  [grid_file.data, meta]

rescue Mongoid::Errors::DocumentNotFound => e
  raise DataNotFound, "#{e} - #{uid}"
end
write(temp_object, opts = {}) click to toggle source
# File lib/dragonfly/mongoid_data_store.rb, line 15
def write(temp_object, opts = {})
  content_type = opts[:content_type] || opts[:mime_type] || 'application/octet-stream'
  meta = temp_object.meta
  meta = meta.merge(opts[:meta]) if opts[:meta].present?

  temp_object.file do |f|
    grid_file = Mongoid::GridFS.put(f, content_type: content_type, meta: marshal_b64_encode(meta))
    grid_file.id.to_s
  end
end