module SimpleEventSourcing::AggregateRoot::Base::ClassMethods

Public Instance Methods

create_from_agrregate_id(id) click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 48
def create_from_agrregate_id(id)
  aggregate = new
  aggregate.aggregate_id = self.generate_id(id)
  aggregate
end
create_from_history(history) click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 54
def create_from_history(history)
  aggregate = self.create_from_agrregate_id history.aggregate_id
  history.each { |event| aggregate.apply_event event }
  aggregate
end
event_mapping() click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 64
def event_mapping
  @event_mapping ||= {}
end
handles_event?(event) click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 68
def handles_event?(event)
  event_mapping.keys.include? event.class
end
on(*message_classes, &block) click to toggle source
# File lib/simple_event_sourcing/aggregate_root/base.rb, line 60
def on(*message_classes, &block)
  message_classes.each { |message_class| event_mapping[message_class] = block }
end