lib/rico/value.rb in rico-0.4.0 vs lib/rico/value.rb in rico-0.5.0
- old
+ new
@@ -3,18 +3,22 @@
include Rico::Object
# Gets the value of the object
#
# Returns the deserialized value
- alias_method :get, :data
+ def get
+ data["_value"]
+ end
# Sets and stores the new value for the object
#
# value - the new value to store
#
# Returns the result of the store operation
- alias_method :set, :mutate
+ def set(value)
+ mutate build_map(value)
+ end
# Sets the value if it does not exist
#
# value - the value to store
#
@@ -34,11 +38,24 @@
#
# robjects - array of RObjects to resolve
#
# Returns a single RObject result or nil
def self.resolve(robject)
- obj = Riak::RObject.new(robject.bucket, robject.key)
- obj.data = robject.siblings.first.data
+ winner = robject.siblings.sort {|a,b| b.last_modified <=> a.last_modified }.first
+
+ obj = robject.dup
+ obj.siblings = [winner]
obj
+ end
+
+ protected
+
+ # Constructs a document map for the new value
+ #
+ # value - Value to include in map
+ #
+ # Returns a Hash representing the document map
+ def build_map(value)
+ { "_type" => type_key, "_value" => value }
end
end
end