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(**args) ⇒ 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(**args)
  attributes(args).each do |key, value|
    singleton_class.__send__(:define_method, key) { value }
  end

  @event_id   = (args[:event_id]  || generate_id).to_s
     = args[:metadata]   || {}
  @data       = attributes(args)
  [:timestamp] ||= Time.now.utc
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'lib/ruby_event_store/event.rb', line 16

def data
  @data
end

#event_idObject (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

#metadataObject (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?



35
36
37
# File 'lib/ruby_event_store/event.rb', line 35

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

#event_typeObject



18
19
20
# File 'lib/ruby_event_store/event.rb', line 18

def event_type
  self.class
end

#timestampObject



31
32
33
# File 'lib/ruby_event_store/event.rb', line 31

def timestamp
  [:timestamp]
end

#to_hObject



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

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