class Synapse::EventSourcing::GenericAggregateFactory
Aggregate factory that uses a convention to create instances of aggregates
Attributes
aggregate_type[R]
@return [Class]
type_identifier[R]
@return [String]
Public Class Methods
new(aggregate_type)
click to toggle source
@param [Class] aggregate_type
@return [undefined]
# File lib/synapse/event_sourcing/aggregate_factory.rb, line 40 def initialize(aggregate_type) @aggregate_type = aggregate_type @type_identifier = aggregate_type.to_s.demodulize end
Public Instance Methods
create_aggregate(aggregate_id, first_event)
click to toggle source
@param [Object] aggregate_id @param [DomainEventMessage] first_event @return [AggregateRoot]
# File lib/synapse/event_sourcing/aggregate_factory.rb, line 48 def create_aggregate(aggregate_id, first_event) payload = first_event.payload if payload.is_a? AggregateRoot aggregate = payload aggregate.reset_initial_version else aggregate = @aggregate_type.allocate end post_process aggregate end
Protected Instance Methods
post_process(aggregate)
click to toggle source
Performs any processing that must be done on an aggregate instance that was reconstructed from a snapshot event. Implementations may choose to modify the existing instance or return a new instance.
@param [AggregateRoot] aggregate @return [AggregateRoot]
# File lib/synapse/event_sourcing/aggregate_factory.rb, line 69 def post_process(aggregate) aggregate end