class Dragonfly::MopedDataStore
Constants
- INVALID_OBJECT_ID
- OBJECT_ID
- VERSION
Public Class Methods
Public Instance Methods
destroy(uid)
click to toggle source
# File lib/dragonfly/moped_data_store.rb, line 61 def destroy uid session.bucket.delete(uid) end
read(uid)
click to toggle source
# File lib/dragonfly/moped_data_store.rb, line 50 def read uid grid_file = session.bucket.open(uid, 'r') meta = grid_file.metadata.each_with_object({}){ |(k,v), h| h[k.to_sym] = v } [ grid_file.read, meta ] rescue RuntimeError raise DataNotFound end
session()
click to toggle source
# File lib/dragonfly/moped_data_store.rb, line 28 def session @session ||= Moped::Session.new(["#{@host}:#{@port}"]).tap do |session| session.use @db end end
write(temp_object, opts={})
click to toggle source
# File lib/dragonfly/moped_data_store.rb, line 36 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] grid_file = session.bucket.open(BSON::ObjectId.new, "w+") grid_file.content_type = content_type grid_file.metadata = meta grid_file.write(temp_object.data) grid_file._id end