lib/ripple/document/persistence.rb in ripple-0.9.5 vs lib/ripple/document/persistence.rb in ripple-1.0.0.beta

- old
+ new

@@ -1,19 +1,5 @@ -# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - require 'active_support/concern' module Ripple module Document module Persistence @@ -27,11 +13,11 @@ end # Destroys all records one at a time. # Place holder while :delete to bucket is being developed. def destroy_all - all(&:destroy) + list(&:destroy) end attr_writer :quorums alias_method "set_quorums", "quorums=" @@ -72,24 +58,24 @@ def save(*args) really_save(*args) end def really_save(*args) - robject.key = key if robject.key != key - robject.data = attributes_for_persistence + update_robject robject.store(self.class.quorums.slice(:w,:dw)) self.key = robject.key @new = false true end # Reloads the document from Riak # @return self def reload return self if new? - robject.reload(:force => true) - self.__send__(:attributes=, @robject.data.except("_type"), false) + @robject = @robject.reload(:force => true) + self.__send__(:raw_attributes=, @robject.data.except("_type")) + reset_associations self end # Deletes the document from Riak and freezes this instance def destroy @@ -111,12 +97,18 @@ @robject ||= Riak::RObject.new(self.class.bucket, key).tap do |obj| obj.content_type = "application/json" end end + def update_robject + robject.key = key if robject.key != key + robject.content_type = 'application/json' + robject.data = attributes_for_persistence + end + private def attributes_for_persistence - attributes.merge("_type" => self.class.name) + raw_attributes.merge("_type" => self.class.name) end end end end end