module Midnight::BusinessLogic::AggregateRoot
Public Instance Methods
dispatch(_command)
click to toggle source
# File lib/midnight/business_logic/aggregate_root.rb, line 11 def dispatch(_command) raise UnknownCommand end
on(event_class, &block)
click to toggle source
# File lib/midnight/business_logic/aggregate_root.rb, line 28 def on(event_class, &block) self._event_handlers ||= {} self._event_handlers[event_class] = block end
pending_events()
click to toggle source
# File lib/midnight/business_logic/aggregate_root.rb, line 19 def pending_events @pending_events ||= [] end
state()
click to toggle source
# File lib/midnight/business_logic/aggregate_root.rb, line 15 def state @state ||= {} end
Private Instance Methods
apply(*events)
click to toggle source
# File lib/midnight/business_logic/aggregate_root.rb, line 36 def apply(*events) handlers = self.class._event_handlers || {} events.each do |event| handler = handlers[event.class] instance_exec(event, &handler) if handler pending_events << event end end