module Lutaml::Model::ComparableModel
def self.included(base)
def self.included(base) base.extend(ClassMethods) end
def already_compared?(other, compared_objects)
def already_compared?(other, compared_objects) compared_objects[comparison_key(other)] end
def attributes_hash(processed_objects)
def attributes_hash(processed_objects) self.class.attributes.map do |attr, _| attr_value = send(attr) if attr_value.respond_to?(:calculate_hash) attr_value.calculate_hash(processed_objects) else attr_value.hash end end end
def calculate_hash(processed_objects = {}.compare_by_identity)
def calculate_hash(processed_objects = {}.compare_by_identity) return if processed_objects.key?(self) processed_objects[self] = true ([self.class] + attributes_hash(processed_objects)).hash end
def comparison_key(other)
def comparison_key(other) "#{object_id}:#{other.object_id}" end
def eql?(other, compared_objects = {})
-
(Boolean)
- True if objects are equal, false otherwise
Parameters:
-
other
(Object
) -- The object to compare with
def eql?(other, compared_objects = {}) return true if equal?(other) return false unless same_class?(other) return true if already_compared?(other, compared_objects) compared_objects[comparison_key(other)] = true self.class.attributes.all? do |attr, _| attr_value = send(attr) other_value = other.send(attr) if attr_value.respond_to?(:eql?) && same_class?(attr_value) attr_value.eql?(other_value, compared_objects) else attr_value == other_value end end end
def hash
-
(Integer)
- The hash value
def hash calculate_hash end
def same_class?(other)
def same_class?(other) other.instance_of?(self.class) end