Class: Akasha::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/akasha/repository.rb

Overview

Aggregate repository. Not meant to be used directly (see aggregate/syntax_helpers.rb) See specs for usage.

Constant Summary collapse

STREAM_NAME_SEP =
'-'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Repository

Returns a new instance of Repository.



8
9
10
# File 'lib/akasha/repository.rb', line 8

def initialize(store)
  @store = store
end

Instance Method Details

#load_aggregate(klass, id) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/akasha/repository.rb', line 12

def load_aggregate(klass, id)
  agg = klass.new(id)

  start = 0
  chunk_size = 100
  stream(klass, id).read_events(start, chunk_size) do |events|
    agg.apply_events(events)
  end

  agg
end

#save_aggregate(aggregate) ⇒ Object



24
25
26
27
# File 'lib/akasha/repository.rb', line 24

def save_aggregate(aggregate)
  changeset = aggregate.changeset
  stream(aggregate.class, changeset.aggregate_id).write_events(changeset.events)
end