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.5"
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.
8 9 10 11 12 13 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 8 def initialize( = {}) @bucket_name = [:bucket_name] @access_key_id = [:access_key_id] @secret_access_key = [:secret_access_key] @endpoint = .fetch(:endpoint, 'objects-us-west-1.dream.io') end |
Instance Method Details
#create_bucket(name) ⇒ Object
37 38 39 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 37 def create_bucket(name) storage.buckets.create(name) end |
#destroy(uid) ⇒ Object
33 34 35 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 33 def destroy(uid) bucket.objects[uid].delete end |
#read(uid) ⇒ Object
# Retrieve the data and meta as a 2-item array
23 24 25 26 27 28 29 30 31 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 23 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
15 16 17 18 19 20 |
# File 'lib/dragonfly/dreamobjects_data_store.rb', line 15 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 |