Module: Replay::Observer

Defined in:
lib/replay/observer.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/replay/observer.rb', line 4

def self.included(base)
  class << base
    def observe(event_type, &block)
      @observer_blocks ||= Hash.new
      @observer_blocks[Replay::Inflector.underscore(event_type.to_s)] = block
    end

    def published(stream_id, event)
      blk = @observer_blocks[Replay::Inflector.underscore(event.class.to_s)]
      blk.call(stream_id, event, binding) if blk
    end
  end
end