Sha256: cb3be1537ce0aa6fd1d10a8c251495eed133c6c827e105978cb7737c4465298c

Contents?: true

Size: 596 Bytes

Versions: 3

Compression:

Stored size: 596 Bytes

Contents

module Aggro
  # Private: Used as a proxy to apply and save events to an aggregate.
  class EventProxy
    def initialize(aggregate, id)
      @aggregate = aggregate
      @id = id
    end

    def method_missing(method_sym, *args)
      details = merge_details_with_command_context(args.pop || {})
      event = Event.new(method_sym, Time.now, details)

      Aggro.store.write_single @id, event
      Aggro.event_bus.publish @id, event
    end

    private

    def merge_details_with_command_context(details)
      @aggregate.instance_variable_get(:@_context).merge(details)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aggro-0.0.4 lib/aggro/event_proxy.rb
aggro-0.0.3 lib/aggro/event_proxy.rb
aggro-0.0.2 lib/aggro/event_proxy.rb