Class: RailsSimpleEventSourcing::AggregateRepository
- Inherits:
-
Object
- Object
- RailsSimpleEventSourcing::AggregateRepository
- Defined in:
- lib/rails_simple_event_sourcing/aggregate_repository.rb
Instance Method Summary collapse
- #find_or_build(aggregate_id) ⇒ Object
-
#initialize(aggregate_class) ⇒ AggregateRepository
constructor
A new instance of AggregateRepository.
- #save!(aggregate) ⇒ Object
Constructor Details
#initialize(aggregate_class) ⇒ AggregateRepository
Returns a new instance of AggregateRepository.
5 6 7 |
# File 'lib/rails_simple_event_sourcing/aggregate_repository.rb', line 5 def initialize(aggregate_class) @aggregate_class = aggregate_class end |
Instance Method Details
#find_or_build(aggregate_id) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/rails_simple_event_sourcing/aggregate_repository.rb', line 9 def find_or_build(aggregate_id) if aggregate_id.present? find_with_lock(aggregate_id) else build_new end end |
#save!(aggregate) ⇒ Object
17 18 19 20 |
# File 'lib/rails_simple_event_sourcing/aggregate_repository.rb', line 17 def save!(aggregate) aggregate.enable_write_access! aggregate.save! end |