Module: EventSourcery::EventProcessing::EventStreamProcessor::ClassMethods

Defined in:
lib/event_sourcery/event_processing/event_stream_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#all_event_handlerObject (readonly)



44
45
46
# File 'lib/event_sourcery/event_processing/event_stream_processor.rb', line 44

def all_event_handler
  @all_event_handler
end

#event_handlersObject (readonly)



44
45
46
# File 'lib/event_sourcery/event_processing/event_stream_processor.rb', line 44

def event_handlers
  @event_handlers
end

#processes_event_typesObject (readonly)



44
45
46
# File 'lib/event_sourcery/event_processing/event_stream_processor.rb', line 44

def processes_event_types
  @processes_event_types
end

Instance Method Details

#process(*event_classes, &block) ⇒ Object

Process the events for the given event types with the given block.

Parameters:

  • event_classes

    the event type classes to process

  • block

    the code block used to process

Raises:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/event_sourcery/event_processing/event_stream_processor.rb', line 74

def process(*event_classes, &block)
  if event_classes.empty?
    if @all_event_handler
      raise MultipleCatchAllHandlersDefined, 'Attemping to define multiple catch all event handlers.'
    else
      @all_event_handler = block
    end
  else
    @processes_event_types ||= []
    event_classes.each do |event_class|
      @processes_event_types << event_class.type
      @event_handlers[event_class.type] << block
    end
  end
end

#processes?(event_type) ⇒ True, False

Can this class process this event type.

Parameters:

  • event_type

    the event type to check

Returns:

  • (True, False)


51
52
53
54
# File 'lib/event_sourcery/event_processing/event_stream_processor.rb', line 51

def processes?(event_type)
  processes_event_types &&
    processes_event_types.include?(event_type.to_s)
end

#processor_name(name = nil) ⇒ Object

Set the name of the processor. Returns the class name if no name is given.

Parameters:

  • name (String) (defaults to: nil)

    the name of the processor to set



60
61
62
63
64
65
66
# File 'lib/event_sourcery/event_processing/event_stream_processor.rb', line 60

def processor_name(name = nil)
  if name
    @processor_name = name
  else
    (defined?(@processor_name) && @processor_name) || self.name
  end
end