Module: SimpleEventSourcing::AggregateRoot::Base::ClassMethods

Defined in:
lib/simple_event_sourcing/aggregate_root/base.rb

Instance Method Summary collapse

Instance Method Details

#create_from_agrregate_id(id) ⇒ Object



48
49
50
51
52
# File 'lib/simple_event_sourcing/aggregate_root/base.rb', line 48

def create_from_agrregate_id(id)
  aggregate = new
  aggregate.aggregate_id = id
  aggregate
end

#create_from_history(history) ⇒ Object



54
55
56
57
58
# 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_mappingObject



64
65
66
# File 'lib/simple_event_sourcing/aggregate_root/base.rb', line 64

def event_mapping
  @event_mapping ||= {}
end

#handles_event?(event) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# 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) ⇒ Object



60
61
62
# 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