Class: Juno::Adapters::Riak

Inherits:
Base
  • Object
show all
Defined in:
lib/juno/adapters/riak.rb

Overview

Riak backend

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #close, #fetch

Constructor Details

#initialize(options = {}) ⇒ Riak

Constructor

Options:

  • :bucket - Bucket name (default juno)

  • :content_type - Default content type (default application/octet-stream)

  • All other options passed to Riak::Client#new

Parameters:

  • options (Hash) (defaults to: {})


19
20
21
22
23
# File 'lib/juno/adapters/riak.rb', line 19

def initialize(options = {})
  bucket = options.delete(:bucket) || 'juno'
  @content_type = options.delete(:content_type) || 'application/octet-stream'
  @bucket = ::Riak::Client.new(options).bucket(bucket)
end

Instance Method Details

#clear(options = {}) ⇒ Object



49
50
51
52
53
54
# File 'lib/juno/adapters/riak.rb', line 49

def clear(options = {})
  @bucket.keys do |keys|
    keys.each{ |key| @bucket.delete(key) }
  end
  self
end

#delete(key, options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/juno/adapters/riak.rb', line 35

def delete(key, options = {})
  value = load(key, options)
  @bucket.delete(key, options)
  value
end

#key?(key, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/juno/adapters/riak.rb', line 25

def key?(key, options = {})
  @bucket.exists?(key, options)
end

#load(key, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/juno/adapters/riak.rb', line 29

def load(key, options = {})
  @bucket.get(key, options).raw_data
rescue ::Riak::FailedRequest => ex
  nil
end

#store(key, value, options = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/juno/adapters/riak.rb', line 41

def store(key, value, options = {})
  obj = ::Riak::RObject.new(@bucket, key)
  obj.content_type = options[:content_type] || @content_type
  obj.raw_data = value
  obj.store(options)
  value
end