Sha256: 48fb2fb7a42337fcb4323879e7392cf568b41c7d884ecae6e9dd207bff4c0a3c

Contents?: true

Size: 800 Bytes

Versions: 2

Compression:

Stored size: 800 Bytes

Contents

module Euston
  module EventHandler
    extend ActiveSupport::Concern
    include Euston::EventHandlerPrivateMethodNames

    included do
      attr_accessor :log unless public_method_defined? :log=
    end

    module ClassMethods
      def subscribes type, version = 1, opts = nil, &consumer
        if self.include? Euston::AggregateRoot
          opts = opts || { :id => :id }

          self.class.send :define_method, id_from_event_method_name(type, version) do |event|
            if opts[:id].respond_to? :call
              opts[:id].call event
            else
              event[opts[:id]]
            end
          end
        end

        define_method event_handler_method_name(type, version) do |*args|
          instance_exec *args, &consumer
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
euston-1.2.0 lib/euston/event_handler.rb
euston-1.2.0-java lib/euston/event_handler.rb