Class: Processor::EventProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/processor/event_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(processor, observers = []) ⇒ EventProcessor

Returns a new instance of EventProcessor.



3
4
5
6
# File 'lib/processor/event_processor.rb', line 3

def initialize(processor, observers = [])
  @observers = observers
  @processor = processor
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/processor/event_processor.rb', line 14

def method_missing(method, *args)
  register "before_#{method}", *args
  result = processor.public_send method, *args
  register "after_#{method}", result, *args

  result
end

Instance Method Details

#register(event, *data) ⇒ Object



8
9
10
11
12
# File 'lib/processor/event_processor.rb', line 8

def register(event, *data)
  observers.each do |observer|
    observer.update event.to_sym, processor, *data
  end
end