Class: Synapse::EventSourcing::GenericAggregateFactory
- Inherits:
-
AggregateFactory
- Object
- AggregateFactory
- Synapse::EventSourcing::GenericAggregateFactory
- Defined in:
- lib/synapse/event_sourcing/aggregate_factory.rb
Overview
Aggregate factory that uses a convention to create instances of aggregates
Instance Attribute Summary collapse
- #aggregate_type ⇒ Class readonly
- #type_identifier ⇒ String readonly
Instance Method Summary collapse
- #create_aggregate(aggregate_id, first_event) ⇒ AggregateRoot
- #initialize(aggregate_type) ⇒ undefined constructor
Constructor Details
#initialize(aggregate_type) ⇒ undefined
40 41 42 43 |
# 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 |
Instance Attribute Details
#aggregate_type ⇒ Class (readonly)
33 34 35 |
# File 'lib/synapse/event_sourcing/aggregate_factory.rb', line 33 def aggregate_type @aggregate_type end |
#type_identifier ⇒ String (readonly)
36 37 38 |
# File 'lib/synapse/event_sourcing/aggregate_factory.rb', line 36 def type_identifier @type_identifier end |
Instance Method Details
#create_aggregate(aggregate_id, first_event) ⇒ AggregateRoot
48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |