Module: AggregateRoot

Defined in:
lib/aggregate_root.rb,
lib/aggregate_root/version.rb,
lib/aggregate_root/configuration.rb,
lib/aggregate_root/default_apply_strategy.rb

Defined Under Namespace

Classes: Configuration, DefaultApplyStrategy

Constant Summary collapse

VERSION =
"0.15.0"
MissingHandler =
Class.new(StandardError)

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



3
4
5
# File 'lib/aggregate_root/configuration.rb', line 3

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



6
7
8
9
# File 'lib/aggregate_root/configuration.rb', line 6

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

Instance Method Details

#apply(event) ⇒ Object



7
8
9
10
# File 'lib/aggregate_root.rb', line 7

def apply(event)
  apply_strategy.(self, event)
  unpublished_events << event
end

#load(stream_name, event_store: default_event_store) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/aggregate_root.rb', line 12

def load(stream_name, event_store: default_event_store)
  @loaded_from_stream_name = stream_name
  events = event_store.read_stream_events_forward(stream_name)
  events.each do |event|
    apply(event)
  end
  @unpublished_events = nil
  self
end

#store(stream_name = loaded_from_stream_name, event_store: default_event_store) ⇒ Object



22
23
24
25
26
27
# File 'lib/aggregate_root.rb', line 22

def store(stream_name = loaded_from_stream_name, event_store: default_event_store)
  unpublished_events.each do |event|
    event_store.publish_event(event, stream_name: stream_name)
  end
  @unpublished_events = nil
end