Module: Foobara::DetachedEntity::Concerns::Equality

Includes:
Concern
Included in:
Foobara::DetachedEntity
Defined in:
foobara-0.0.110/projects/detached_entity/src/concerns/equality.rb

Instance Method Summary collapse

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Instance Method Details

#==(other) ⇒ Object



12
13
14
15
16
# File 'foobara-0.0.110/projects/detached_entity/src/concerns/equality.rb', line 12

def ==(other)
  # Should both records be required to be persisted to be considered equal when having matching primary keys?
  # For now we will consider them equal but it could make sense to consider them not equal.
  equal?(other) || (self.class == other.class && primary_key && primary_key == other.primary_key)
end

#dupObject



7
8
9
10
# File 'foobara-0.0.110/projects/detached_entity/src/concerns/equality.rb', line 7

def dup
  # TODO: Maybe raise instead?
  self
end

#hashObject



18
19
20
# File 'foobara-0.0.110/projects/detached_entity/src/concerns/equality.rb', line 18

def hash
  (primary_key || object_id).hash
end