Module: Sequent::Core::Helpers::EqualSupport

Included in:
BaseCommand, Event, ValueObject
Defined in:
lib/sequent/core/helpers/equal_support.rb

Overview

You typically do not need to include this module in your classes. If you extend from Sequent::Core::ValueObject, Sequent::Core::Event or Sequent::Core::BaseCommand you will get this functionality for free.

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sequent/core/helpers/equal_support.rb', line 10

def ==(other)
  return false if other == nil
  return false if self.class != other.class
  self.class.types.each do |name, _|
    self_value = self.send(name)
    other_value = other.send(name)
    if self_value.class == DateTime && other_value.class == DateTime
      # we don't care about milliseconds. If you know a better way of checking for equality please improve.
      return false unless (self_value.iso8601 == other_value.iso8601)
    else
      return false unless (self_value == other_value)
    end
  end
  true
end

#eql?(other) ⇒ Boolean

Returns:



34
35
36
# File 'lib/sequent/core/helpers/equal_support.rb', line 34

def eql?(other)
  self == other
end

#hashObject



26
27
28
29
30
31
32
# File 'lib/sequent/core/helpers/equal_support.rb', line 26

def hash
  hash = 17
  self.class.types.each do |name, _|
    hash = hash * 31 + self.send(name).hash
  end
  hash
end