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
-
#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.
12 13 14 |
# File 'lib/riak-shim/persistable.rb', line 12 def key @key ||= self.class.gen_key end |
Instance Method Details
#bucket ⇒ Riak::Bucket
Returns 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_name ⇒ String
Returns 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 |
#destroy ⇒ Persistable
Remove this object from Riak
43 44 45 46 |
# File 'lib/riak-shim/persistable.rb', line 43 def destroy bucket.delete(key) self end |
#save ⇒ Persistable
Persist this object into Riak
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 |
#store ⇒ Riak::Shim::Store
Returns the Riak cluster you are connected to.
27 28 29 |
# File 'lib/riak-shim/persistable.rb', line 27 def store self.class.store end |