Class: RubyCqrs::Domain::AggregateRepository

Inherits:
Object
  • Object
show all
Includes:
RubyCqrs::Data::Decodable
Defined in:
lib/ruby_cqrs/domain/aggregate_repository.rb

Instance Method Summary collapse

Methods included from RubyCqrs::Data::Decodable

#try_decode

Instance Method Details

#find_by(aggregate_id) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_cqrs/domain/aggregate_repository.rb', line 13

def find_by aggregate_id
  raise ArgumentError if aggregate_id.nil?
  raise ArgumentError unless Guid.validate? aggregate_id

  state = @event_store.load_by(aggregate_id, @command_context)
  raise AggregateNotFound 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(one_or_many_aggregate) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
# File 'lib/ruby_cqrs/domain/aggregate_repository.rb', line 24

def save one_or_many_aggregate
  raise ArgumentError if one_or_many_aggregate.nil?
  return delegate_persistence_of [ one_or_many_aggregate ] if one_or_many_aggregate.is_a? Aggregate

  raise ArgumentError unless one_or_many_aggregate.is_a? Enumerable and one_or_many_aggregate.size > 0
  delegate_persistence_of one_or_many_aggregate
end