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

- old
+ new

@@ -1,25 +1,13 @@ -# 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' require 'active_model/naming' +require 'ripple/conflict/document_hooks' require 'ripple/document/bucket_access' require 'ripple/document/key' require 'ripple/document/persistence' require 'ripple/document/finders' +require 'ripple/document/link' require 'ripple/properties' require 'ripple/attribute_methods' require 'ripple/timestamps' require 'ripple/validations' require 'ripple/associations' @@ -62,21 +50,22 @@ extend ActiveModel::Naming extend BucketAccess include Ripple::Document::Key include Ripple::Document::Persistence extend Ripple::Properties + include Ripple::Document::Finders include Ripple::AttributeMethods include Ripple::Timestamps include Ripple::Validations include Ripple::Associations include Ripple::Callbacks include Ripple::Observable include Ripple::Conversion - include Ripple::Document::Finders include Ripple::Inspection include Ripple::NestedAttributes include Ripple::Serialization + include Ripple::Conflict::DocumentHooks end module ClassMethods def embeddable? false @@ -90,10 +79,26 @@ # Returns true if the +comparison_object+ is the same object, or is of the same type and has the same key. def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.class < Document && (comparison_object.instance_of?(self.class) || comparison_object.class.bucket.name == self.class.bucket.name) && - comparison_object.key == key && !comparison_object.new?) + !new? && comparison_object.key == key && !comparison_object.new?) + end + + def eql?(other) + return true if other.equal?(self) + + (other.class.equal?(self.class)) && + !other.new? && !new? && + (other.key == key) + end + + def hash + if new? + super # every new document should be treated as a different doc + else + [self.class, key].hash + end end end end end