Module: Riak::Shim::Persistable

Defined in:
lib/riak-shim/persistable.rb,
lib/riak-shim/secondary_index_query.rb

Overview

Provides basic persistence features

Defined Under Namespace

Modules: ClassMethods Classes: SecondaryIndexQuery

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyString

Returns the unique key for storing the object in Riak.

Returns:

  • (String)

    the unique key for storing the object in Riak



12
13
14
# File 'lib/riak-shim/persistable.rb', line 12

def key
  @key ||= self.class.gen_key
end

Instance Method Details

#bucketRiak::Bucket

Returns your app’s Riak bucket for this class.

Returns:

  • (Riak::Bucket)

    your app’s Riak bucket for this class



17
18
19
# File 'lib/riak-shim/persistable.rb', line 17

def bucket
  return self.class.store.bucket(bucket_name)
end

#bucket_nameString

Returns name of the Riak bucket generated from the class name and your configuration.

Returns:

  • (String)

    name of the Riak bucket generated from the class name and your configuration



22
23
24
# File 'lib/riak-shim/persistable.rb', line 22

def bucket_name
  self.class.bucket_name
end

#destroyPersistable

Remove this object from Riak

Returns:



43
44
45
46
# File 'lib/riak-shim/persistable.rb', line 43

def destroy
  bucket.delete(key)
  self
end

#savePersistable

Persist this object into Riak

Returns:



33
34
35
36
37
38
39
# File 'lib/riak-shim/persistable.rb', line 33

def save
  doc = bucket.get_or_new(key)
  doc.data = to_hash
  set_indexes(doc.indexes)
  doc.store
  self
end

#storeRiak::Shim::Store

Returns the Riak cluster you are connected to.

Returns:



27
28
29
# File 'lib/riak-shim/persistable.rb', line 27

def store
  self.class.store
end