Class: EventSorcerer::AggregateLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/event_sorcerer/aggregate_loader.rb

Overview

Public: Service class for loading aggregates from the event store.

Instance Method Summary collapse

Constructor Details

#initialize(klass, id, events, version, prohibit_new = true) ⇒ AggregateLoader

Public: Creates a new AggregateLoader instance.

klass - class for the aggregate to be loaded. id - id for the aggregate to be loaded. prohibit_new - whether or not to raise an error if aggregate not existing.



9
10
11
12
13
14
15
# File 'lib/event_sorcerer/aggregate_loader.rb', line 9

def initialize(klass, id, events, version, prohibit_new = true)
  @events       = events
  @id           = id
  @klass        = klass
  @prohibit_new = prohibit_new
  @version      = version
end

Instance Method Details

#loadObject

Public: Wraps and returns aggregate in a proxy.

Returns an AggregateProxy. Raises AggregateNotFound if aggregate not found and prohibit_new is true.



21
22
23
24
25
# File 'lib/event_sorcerer/aggregate_loader.rb', line 21

def load
  fail AggregateNotFound if prohibit_new && new_aggregate?

  AggregateProxy.new(aggregate)
end