Module: Riak::Shim::Persistable
- Defined in:
- lib/riak-shim/persistable.rb
Overview
Provides basic persistence features
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#key ⇒ String
The unique key for storing the object in Riak.
Instance Method Summary collapse
-
#bucket ⇒ Riak::Bucket
Your app’s Riak bucket for this class.
-
#bucket_name ⇒ String
Name of the Riak bucket generated from the class name and your configuration.
-
#destroy ⇒ Persistable
Remove this object from Riak.
-
#save ⇒ Persistable
Persist this object into Riak.
-
#store ⇒ Riak::Shim::Store
The Riak cluster you are connected to.
Instance Attribute Details
#key ⇒ String
Returns the unique key for storing the object in Riak.
11 12 13 |
# File 'lib/riak-shim/persistable.rb', line 11 def key @key ||= self.class.gen_key end |
Instance Method Details
#bucket ⇒ Riak::Bucket
Returns your app’s Riak bucket for this class.
16 17 18 |
# File 'lib/riak-shim/persistable.rb', line 16 def bucket return self.class.store.bucket(bucket_name) end |
#bucket_name ⇒ String
Returns name of the Riak bucket generated from the class name and your configuration.
21 22 23 |
# File 'lib/riak-shim/persistable.rb', line 21 def bucket_name self.class.bucket_name end |
#destroy ⇒ Persistable
Remove this object from Riak
42 43 44 45 |
# File 'lib/riak-shim/persistable.rb', line 42 def destroy bucket.delete(key) self end |
#save ⇒ Persistable
Persist this object into Riak
32 33 34 35 36 37 38 |
# File 'lib/riak-shim/persistable.rb', line 32 def save doc = bucket.get_or_new(key) doc.data = to_hash set_indexes(doc.indexes) doc.store self end |
#store ⇒ Riak::Shim::Store
Returns the Riak cluster you are connected to.
26 27 28 |
# File 'lib/riak-shim/persistable.rb', line 26 def store self.class.store end |