Class: RubyEventStore::Event
- Inherits:
-
Object
- Object
- RubyEventStore::Event
- Defined in:
- lib/ruby_event_store/event.rb
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?)
-
#initialize(event_id: SecureRandom.uuid, metadata: {}, **data) ⇒ Event
constructor
A new instance of Event.
- #timestamp ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(event_id: SecureRandom.uuid, metadata: {}, **data) ⇒ Event
Returns a new instance of Event.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ruby_event_store/event.rb', line 6 def initialize(event_id: SecureRandom.uuid, metadata: {}, **data) data.each do |key, value| singleton_class.__send__(:define_method, key) { value } end @event_id = event_id.to_s = @data = data [:timestamp] ||= Time.now.utc end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
16 17 18 |
# File 'lib/ruby_event_store/event.rb', line 16 def data @data end |
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
16 17 18 |
# File 'lib/ruby_event_store/event.rb', line 16 def event_id @event_id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
16 17 18 |
# File 'lib/ruby_event_store/event.rb', line 16 def end |
Instance Method Details
#==(other_event) ⇒ Object Also known as: eql?
30 31 32 |
# File 'lib/ruby_event_store/event.rb', line 30 def ==(other_event) other_event.instance_of?(self.class) && other_event.to_h.eql?(to_h) end |
#timestamp ⇒ Object
26 27 28 |
# File 'lib/ruby_event_store/event.rb', line 26 def [:timestamp] end |
#to_h ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ruby_event_store/event.rb', line 18 def to_h { event_id: event_id, metadata: , data: data } end |