Class: RubyCqrs::Domain::AggregateRepository
- Inherits:
-
Object
- Object
- RubyCqrs::Domain::AggregateRepository
- Includes:
- Contracts, Contracts::Modules, RubyCqrs::Data::Decodable
- Defined in:
- lib/ruby_cqrs/domain/aggregate_repository.rb
Instance Method Summary collapse
- #find_by(aggregate_id) ⇒ Object
-
#initialize(event_store, command_context) ⇒ AggregateRepository
constructor
A new instance of AggregateRepository.
- #save(many_aggregate) ⇒ Object
Methods included from RubyCqrs::Data::Decodable
Constructor Details
#initialize(event_store, command_context) ⇒ AggregateRepository
Returns a new instance of AggregateRepository.
18 19 20 21 22 |
# File 'lib/ruby_cqrs/domain/aggregate_repository.rb', line 18 def initialize event_store, command_context raise ArgumentError unless event_store.is_a? Data::EventStore @event_store = event_store @command_context = command_context end |
Instance Method Details
#find_by(aggregate_id) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ruby_cqrs/domain/aggregate_repository.rb', line 25 def find_by aggregate_id state = @event_store.load_by(aggregate_id, @command_context) raise AggregateNotFoundError if (state.nil? or state[:aggregate_type].nil? or\ ((state[:events].nil? or state[:events].empty?) and state[:snapshot].nil?)) create_instance_from state end |
#save(many_aggregate) ⇒ Object
34 35 36 |
# File 'lib/ruby_cqrs/domain/aggregate_repository.rb', line 34 def save one_aggregate delegate_persistence_of [ one_aggregate ] end |