Class: Dragonfly::DreamobjectsDataStore
- Inherits:
-
Object
- Object
- Dragonfly::DreamobjectsDataStore
- Defined in:
- lib/dragonfly/dreamobjects_data_store.rb,
lib/dragonfly/dreamobjects_data_store/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #create_bucket(name) ⇒ Object
- #destroy(uid) ⇒ Object
-
#initialize(options = {}) ⇒ DreamobjectsDataStore
constructor
A new instance of DreamobjectsDataStore.
-
#read(uid) ⇒ Object
# Retrieve the data and meta as a 2-item array.
- #write(content, opts = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DreamobjectsDataStore
Returns a new instance of DreamobjectsDataStore.
9 10 11 12 13 14 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 9 def initialize( = {}) @bucket_name = [:bucket_name] @access_key_id = [:access_key_id] @secret_access_key = [:secret_access_key] @endpoint = .fetch(:endpoint, 'objects.dreamhost.com') end |
Instance Method Details
#create_bucket(name) ⇒ Object
38 39 40 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 38 def create_bucket(name) storage.buckets.create(name) end |
#destroy(uid) ⇒ Object
34 35 36 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 34 def destroy(uid) bucket.objects[uid].delete end |
#read(uid) ⇒ Object
# Retrieve the data and meta as a 2-item array
24 25 26 27 28 29 30 31 32 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 24 def read(uid) object = bucket.objects[uid] data = object.read = Serializer.json_decode(object.[:json]) [ data, # can be a String, File, Pathname, Tempfile # the same meta Hash that was stored with write ] end |
#write(content, opts = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 16 def write(content, opts={}) uid = opts[:path] || generate_uid(content.name || 'file') bucket.objects[uid].write(content.data, metadata: { json: Serializer.json_encode(content.)}) uid end |