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
36 37 38 39 |
# File 'lib/synapse/event_sourcing/aggregate_factory.rb', line 36 def initialize(aggregate_type) @aggregate_type = aggregate_type @type_identifier = aggregate_type.to_s.demodulize end |
Instance Attribute Details
#aggregate_type ⇒ Class (readonly)
29 30 31 |
# File 'lib/synapse/event_sourcing/aggregate_factory.rb', line 29 def aggregate_type @aggregate_type end |
#type_identifier ⇒ String (readonly)
32 33 34 |
# File 'lib/synapse/event_sourcing/aggregate_factory.rb', line 32 def type_identifier @type_identifier end |
Instance Method Details
#create_aggregate(aggregate_id, first_event) ⇒ AggregateRoot
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/synapse/event_sourcing/aggregate_factory.rb', line 44 def create_aggregate(aggregate_id, first_event) payload = first_event.payload if payload.is_a? AggregateRoot aggregate = payload else aggregate = @aggregate_type.allocate end post_process aggregate end |