Class: Rico::Value

Inherits:
Object
  • Object
show all
Includes:
Object
Defined in:
lib/rico/value.rb

Instance Attribute Summary

Attributes included from Object

#bucket, #key

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Object

#data, #exists?, #initialize, #mutate

Class Method Details

.resolve(robject) ⇒ Object

Resolve conflict between one or more RObject siblings

This currently just returns the first sibling

robjects - array of RObjects to resolve

Returns a single RObject result or nil



42
43
44
45
46
47
48
# File 'lib/rico/value.rb', line 42

def self.resolve(robject)
  winner = robject.siblings.sort {|a,b| b.last_modified <=> a.last_modified }.first

  obj = robject.dup
  obj.siblings = [winner]
  obj
end

Instance Method Details

#getObject

Gets the value of the object

Returns the deserialized value



8
9
10
# File 'lib/rico/value.rb', line 8

def get
  data["_value"]
end

#set(value) ⇒ Object

Sets and stores the new value for the object

value - the new value to store

Returns the result of the store operation



17
18
19
# File 'lib/rico/value.rb', line 17

def set(value)
  mutate build_map(value)
end

#setnx(value) ⇒ Object

Sets the value if it does not exist

value - the value to store

Returns true if stored, false if not



26
27
28
29
30
31
32
33
# File 'lib/rico/value.rb', line 26

def setnx(value)
  if exists?
    false
  else
    set value
    true
  end
end