Module: Rico::Object
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#data ⇒ Object
Retrieves data from Riak.
-
#exists? ⇒ Boolean
Determine whether an object exists or not.
-
#initialize(bucket, key, options = {}) ⇒ Object
Initialize an object with a bucket and key.
-
#mutate(value) ⇒ Object
Sets a new value on the object and stores it.
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
7 8 9 |
# File 'lib/rico/object.rb', line 7 def bucket @bucket end |
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/rico/object.rb', line 7 def key @key end |
Instance Method Details
#data ⇒ Object
Retrieves data from Riak
Raises an error on type mismatch
23 24 25 26 27 28 29 30 31 |
# File 'lib/rico/object.rb', line 23 def data result = riak_object.data || {} if result["_type"] && (result["_type"] != type_key) raise TypeError, "#{@bucket}:#{@key} expected type to be #{type_key}, got #{result["_type"]}" end result end |
#exists? ⇒ Boolean
Determine whether an object exists or not
Returns true or false
46 47 48 |
# File 'lib/rico/object.rb', line 46 def exists? Rico.bucket(@bucket).exists? @key end |
#initialize(bucket, key, options = {}) ⇒ Object
Initialize an object with a bucket and key
bucket - the name of the bucket (not prefixed by a namespace) key - the name of the key
Returns nothing
15 16 17 18 |
# File 'lib/rico/object.rb', line 15 def initialize(bucket, key, ={}) @bucket, @key = bucket, key .each {|k,v| send("#{k}=", v)} end |
#mutate(value) ⇒ Object
Sets a new value on the object and stores it
value - new value to set
Returns the result of the store operation
38 39 40 41 |
# File 'lib/rico/object.rb', line 38 def mutate(value) riak_object.data = value store end |