module SimpleEventSourcing::AggregateRoot::Base
Attributes
aggregate_id[RW]
Public Class Methods
included(o)
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 42 def self.included(o) o.extend(ClassMethods) end
new(_args = nil)
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 8 def initialize(_args = nil) @events = [] end
Public Instance Methods
apply_event(event)
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 26 def apply_event(event) handler = self.class.event_mapping[event.class] self.instance_exec(event, &handler) if handler end
apply_record_event(event_class, args = {})
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 31 def apply_record_event(event_class, args = {}) args[:aggregate_id] ||= aggregate_id.value event = event_class.new(args) apply_event event record_event event end
count_events()
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 16 def count_events @events.count end
have_changed?()
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 12 def have_changed? (@events.count > 0) end
id()
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 38 def id @aggregate_id.value end
publish()
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 20 def publish published_events = @events clear_events published_events end
Private Instance Methods
clear_events()
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 79 def clear_events @events = [] end
record_event(event)
click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 75 def record_event(event) @events << event end