Class: RubyEventStore::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Event.



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

def initialize(event_id: SecureRandom.uuid, metadata: {}, data: {})
  @event_id = event_id.to_s
  @metadata = ClosedStruct.new()
  @data     = ClosedStruct.new(data)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#event_idObject (readonly)

Returns the value of attribute event_id.



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

def event_id
  @event_id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  @metadata
end

Instance Method Details

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



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

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

#timestampObject



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

def timestamp
  .timestamp rescue nil
end

#to_hObject



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

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