Sha256: 1b9d2741b20aff067004b5634e28ccd0f60041feba654e5216bed56d5e18b27e

Contents?: true

Size: 791 Bytes

Versions: 6

Compression:

Stored size: 791 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
          o = { :id => :id }.merge opts

          self.class.send :define_method, id_from_event_method_name(type, version) do |event|
            if o[:id].respond_to? :call
              o[:id].call event
            else
              event[o[: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

6 entries across 6 versions & 1 rubygems

Version Path
euston-1.2.3 lib/euston/event_handler.rb
euston-1.2.3-java lib/euston/event_handler.rb
euston-1.2.2 lib/euston/event_handler.rb
euston-1.2.2-java lib/euston/event_handler.rb
euston-1.2.1 lib/euston/event_handler.rb
euston-1.2.1-java lib/euston/event_handler.rb