Class: Dragonfly::DreamobjectsDataStore

Inherits:
Object
  • Object
show all
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

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(options = {})
  @bucket_name       = options[:bucket_name]
  @access_key_id     = options[:access_key_id]
  @secret_access_key = options[:secret_access_key]
  @endpoint          = options.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
  meta = Serializer.json_decode(object.[:json])
    [
      data,     # can be a String, File, Pathname, Tempfile
      meta      # 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.meta)})
  uid
end