Module: SimpleEventSourcing::AggregateRoot::Base::ClassMethods
- Defined in:
- lib/simple_event_sourcing/aggregate_root/base.rb
Instance Method Summary collapse
- #create_from_agrregate_id(id) ⇒ Object
- #create_from_history(history) ⇒ Object
- #event_mapping ⇒ Object
- #handles_event?(event) ⇒ Boolean
- #on(*message_classes, &block) ⇒ Object
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_mapping ⇒ Object
64 65 66 |
# File 'lib/simple_event_sourcing/aggregate_root/base.rb', line 64 def event_mapping @event_mapping ||= {} end |
#handles_event?(event) ⇒ 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(*, &block) .each { || event_mapping[] = block } end |