Class: Rico::Value
Instance Attribute Summary
Attributes included from Object
Class Method Summary collapse
-
.resolve(robject) ⇒ Object
Resolve conflict between one or more RObject siblings.
Instance Method Summary collapse
-
#get ⇒ Object
Gets the value of the object.
-
#set(value) ⇒ Object
Sets and stores the new value for the object.
-
#setnx(value) ⇒ Object
Sets the value if it does not exist.
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
#get ⇒ Object
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 |