Module: Replay::Observer::ClassMethods
- Defined in:
- lib/replay/observer.rb
Instance Method Summary collapse
Instance Method Details
#observe(event_type, &block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/replay/observer.rb', line 15 def observe(event_type, &block) raise InvalidRouterError.new("No router defined!") unless @router @observer_blocks ||= Hash.new @observer_blocks[Replay::Inflector.underscore(event_type.to_s)] = block @router.add_observer self, event_type end |
#published(stream_id, event) ⇒ Object
23 24 25 26 |
# File 'lib/replay/observer.rb', line 23 def published(stream_id, event) blk = @observer_blocks[Replay::Inflector.underscore(event.type)] blk.call(stream_id, event, binding) if blk 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 |