Class: RailsSimpleEventSourcing::Event
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- RailsSimpleEventSourcing::Event
- Includes:
- AggregateConfiguration, EventAttributes, ReadOnly, SchemaVersioning
- Defined in:
- app/models/rails_simple_event_sourcing/event.rb
Instance Method Summary collapse
Methods included from SchemaVersioning
Methods included from AggregateConfiguration
Instance Method Details
#aggregate_state ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/models/rails_simple_event_sourcing/event.rb', line 35 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
27 28 29 30 31 32 33 |
# File 'app/models/rails_simple_event_sourcing/event.rb', line 27 def apply(aggregate) payload.each do |key, value| raise ArgumentError, "Unknown attribute '#{key}' on #{aggregate.class}" unless aggregate.respond_to?("#{key}=") aggregate.send("#{key}=", value) end end |