Class: RubyEventStore::Event
- Inherits:
-
Object
- Object
- RubyEventStore::Event
- Defined in:
- lib/ruby_event_store/event.rb
Constant Summary collapse
- BIG_VALUE =
0b111111100100000010010010110011101011000101010101001100100110000
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#event_id ⇒ Object
readonly
Returns the value of attribute event_id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #==(other_event) ⇒ Object (also: #eql?)
-
#hash ⇒ Object
We don’t use metadata because == does not use metadata.
-
#initialize(event_id: SecureRandom.uuid, metadata: nil, data: nil) ⇒ Event
constructor
A new instance of Event.
- #timestamp ⇒ Object
- #to_h ⇒ Object
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/ruby_event_store/event.rb', line 10 def data @data end |
#event_id ⇒ Object (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 |
#metadata ⇒ Object (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 |
#hash ⇒ Object
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 |
#timestamp ⇒ Object
20 21 22 |
# File 'lib/ruby_event_store/event.rb', line 20 def [:timestamp] end |
#to_h ⇒ Object
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 |