Class: CarrierWave::Storage::Riak::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/storage/riak.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



19
20
21
# File 'lib/carrierwave/storage/riak.rb', line 19

def initialize(options={})
  @client = ::Riak::Client.new(options)
end

Instance Method Details

#delete(bucket, key) ⇒ Object



36
37
38
39
# File 'lib/carrierwave/storage/riak.rb', line 36

def delete(bucket, key)
  bucket = @client.bucket(bucket)
  bucket.delete(key)
end

#escaped(path) ⇒ Object



45
46
47
# File 'lib/carrierwave/storage/riak.rb', line 45

def escaped(path)
  CGI.escape(path)
end

#get(bucket, key) ⇒ Object



31
32
33
34
# File 'lib/carrierwave/storage/riak.rb', line 31

def get(bucket, key)
  bucket = @client.bucket(bucket)
  bucket.get(key)
end

#post(path, payload, headers = {}) ⇒ Object



41
42
43
# File 'lib/carrierwave/storage/riak.rb', line 41

def post(path, payload, headers = {})
  @http["#{escaped(path)}"].post(payload, headers)
end

#store(bucket, key, payload, headers = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/carrierwave/storage/riak.rb', line 23

def store(bucket, key, payload, headers = {})
  bucket = @client.bucket(bucket)
  robject = ::Riak::RObject.new(bucket, key)
  robject.content_type = headers[:content_type]
  robject.raw_data = payload
  robject.store
end