Module: Rico::Object

Extended by:
Forwardable
Included in:
Collection, Counter, Value
Defined in:
lib/rico/object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



7
8
9
# File 'lib/rico/object.rb', line 7

def bucket
  @bucket
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/rico/object.rb', line 7

def key
  @key
end

Instance Method Details

#dataObject

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

Returns:

  • (Boolean)


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, options={})
  @bucket, @key = bucket, key
  options.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