Class: RubyEventStore::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/event.rb

Constant Summary collapse

BIG_VALUE =
0b111111100100000010010010110011101011000101010101001100100110000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_id: SecureRandom.uuid, metadata: nil, data: nil) ⇒ Event

Returns a new instance of Event.



5
6
7
8
9
# File 'lib/ruby_event_store/event.rb', line 5

def initialize(event_id: SecureRandom.uuid, metadata: nil, data: nil)
  @event_id = event_id.to_s
  @metadata = .to_h
  @data     = data.to_h
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/ruby_event_store/event.rb', line 10

def data
  @data
end

#event_idObject (readonly)

Returns the value of attribute event_id.



10
11
12
# File 'lib/ruby_event_store/event.rb', line 10

def event_id
  @event_id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



10
11
12
# File 'lib/ruby_event_store/event.rb', line 10

def 
  @metadata
end

Instance Method Details

#==(other_event) ⇒ Object Also known as: eql?



24
25
26
27
28
# File 'lib/ruby_event_store/event.rb', line 24

def ==(other_event)
  other_event.instance_of?(self.class) &&
    other_event.event_id.eql?(event_id) &&
    other_event.data.eql?(data)
end

#hashObject

We don’t use metadata because == does not use metadata



33
34
35
36
37
38
39
# File 'lib/ruby_event_store/event.rb', line 33

def hash
  [
    self.class,
    event_id,
    data
  ].hash ^ BIG_VALUE
end

#timestampObject



20
21
22
# File 'lib/ruby_event_store/event.rb', line 20

def timestamp
  [:timestamp]
end

#to_hObject



12
13
14
15
16
17
18
# File 'lib/ruby_event_store/event.rb', line 12

def to_h
  {
      event_id:   event_id,
      metadata:   ,
      data:       data
  }
end