Class: RailsSimpleEventSourcing::Event

Inherits:
ApplicationRecord
  • Object
show all
Includes:
AggregateConfiguration, EventAttributes, ReadOnly
Defined in:
app/models/rails_simple_event_sourcing/event.rb

Instance Method Summary collapse

Methods included from AggregateConfiguration

#aggregate_class, #aggregate_defined?

Instance Method Details

#aggregate_stateObject



24
25
26
27
28
29
30
31
# File 'app/models/rails_simple_event_sourcing/event.rb', line 24

def aggregate_state
  return unless aggregate_defined? && aggregate_id.present?

  aggregate = aggregate_class.new
  aggregate.id = aggregate_id
  EventPlayer.new(aggregate).replay_stream(up_to_version: version)
  aggregate.attributes
end

#apply(aggregate) ⇒ Object



18
19
20
21
22
# File 'app/models/rails_simple_event_sourcing/event.rb', line 18

def apply(aggregate)
  payload.each do |key, value|
    aggregate.send("#{key}=", value) if aggregate.respond_to?("#{key}=")
  end
end