Class: EventSorcerer::AggregateLoader
- Inherits:
-
Object
- Object
- EventSorcerer::AggregateLoader
- Defined in:
- lib/event_sorcerer/aggregate_loader.rb
Overview
Public: Service class for loading aggregates from the event store.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Public: Returns the id for the aggregate to be loaded.
Instance Method Summary collapse
-
#initialize(klass, id, events, version, prohibit_new = true) ⇒ AggregateLoader
constructor
Public: Creates a new AggregateLoader instance.
-
#load ⇒ Object
Public: Wraps and returns aggregate in a proxy.
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.
12 13 14 15 16 17 18 |
# File 'lib/event_sorcerer/aggregate_loader.rb', line 12 def initialize(klass, id, events, version, prohibit_new = true) @events = events @id = id @klass = klass @prohibit_new = prohibit_new @version = version end |
Instance Attribute Details
#id ⇒ Object (readonly)
Public: Returns the id for the aggregate to be loaded.
5 6 7 |
# File 'lib/event_sorcerer/aggregate_loader.rb', line 5 def id @id end |
Instance Method Details
#load ⇒ Object
Public: Wraps and returns aggregate in a proxy.
Returns an AggregateProxy. Raises AggregateNotFound if aggregate not found and prohibit_new is true.
24 25 26 27 28 |
# File 'lib/event_sorcerer/aggregate_loader.rb', line 24 def load fail AggregateNotFound if prohibit_new && new_aggregate? AggregateProxy.new(aggregate) end |