Class: Sequent::Core::Event

Inherits:
Object
  • Object
show all
Includes:
Helpers::AttributeSupport, Helpers::Copyable, Helpers::EqualSupport, Helpers::StringSupport
Defined in:
lib/sequent/core/event.rb

Direct Known Subclasses

SnapshotEvent

Instance Method Summary collapse

Methods included from Helpers::StringSupport

#to_s

Methods included from Helpers::EqualSupport

#==, #eql?, #hash

Methods included from Helpers::AttributeSupport

#as_json, #attributes, #ensure_known_attributes, included, #update, #validation_errors

Methods included from Helpers::Copyable

#copy

Constructor Details

#initialize(args = {}) ⇒ Event

Returns a new instance of Event.



18
19
20
21
22
23
24
# File 'lib/sequent/core/event.rb', line 18

def initialize(args = {})
  update_all_attributes args
  fail 'Missing aggregate_id' unless @aggregate_id
  fail 'Missing sequence_number' unless @sequence_number

  @created_at ||= Time.now
end

Instance Method Details

#payloadObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/sequent/core/event.rb', line 26

def payload
  result = {}
  instance_variables
    .reject { |k| payload_variables.include?(k) }
    .select { |k| self.class.types.keys.include?(to_attribute_name(k)) }
    .each do |k|
      result[k.to_s[1..-1].to_sym] = instance_variable_get(k)
    end
  result
end