Module: Replay::Observer::ClassMethods

Defined in:
lib/replay/observer.rb

Instance Method Summary collapse

Instance Method Details

#handle(envelope) ⇒ Object



37
38
39
# File 'lib/replay/observer.rb', line 37

def handle(envelope)
  published(envelope)
end

#observe(event_type, &block) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
# File 'lib/replay/observer.rb', line 22

def observe(event_type, &block)
  raise InvalidRouterError.new("No router defined!") unless @router
  @observed_events ||= Set.new
  @observed_events.add(event_type)

  @observer_blocks ||= Hash.new
  @observer_blocks[Replay::Inflector.underscore(event_type.to_s)] = block

  @router.add_observer self, event_type
end

#observed_eventsObject



33
34
35
# File 'lib/replay/observer.rb', line 33

def observed_events
  @observed_events.dup
end

#published(envelope) ⇒ Object



41
42
43
44
# File 'lib/replay/observer.rb', line 41

def published(envelope)
  blk = @observer_blocks[Replay::Inflector.underscore(envelope.type)]
  blk.call(envelope, binding) if blk
end

#reset!Object

gives the observer a chance to take itself down to a null state in the event of a catchup must be overridden in the base class



18
19
20
# File 'lib/replay/observer.rb', line 18

def reset!
  raise "reset must be implemented in the observing class"
end

#router(rtr) ⇒ Object



10
11
12
13
# File 'lib/replay/observer.rb', line 10

def router(rtr)
  raise Replay::InvalidRouterError.new("Router does not implement add_observer") unless rtr.respond_to?(:add_observer) 
  @router = rtr
end