replay 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3beb3bff2248463621c24952c69e0e4186743868
4
- data.tar.gz: 39daf670446e91350ba1b28017d2101a5517e01b
3
+ metadata.gz: dc1383b965327df0adcc628798ba7aa1bced6a77
4
+ data.tar.gz: 0f356feb134a03df3451c63a725c83a7e70de7b1
5
5
  SHA512:
6
- metadata.gz: 089ec9db6ca5d4fe9e2d1c4f5da3b9367c07f12b38a6dbf9a58a679a9260c8857cfdc14184ee38b468da3a829a9548e0f115e5da88cfa5953c42c580c8c46d3d
7
- data.tar.gz: 22bb3d6ed1dd62066e42079ca2facf391437528961768fc58199593108d5f130e2064c455ebc10c53f9b40d4658608a15b25a60a9ce77e4ebd0ef01821f4813b
6
+ metadata.gz: a12609875ef5e36b0a39f20eba5c481f5eb5c5d06d912b66c517cbd91bcbbdf7b63e9afc4437f1ee48c1a6719a582bf49f65ee0179fbe1cf6ffc7dc5e899b00e
7
+ data.tar.gz: 09d59773b29803f51d614fc7bff2bb45d65f063b9967490191015682a1d63a6c0724136d12a3b1661c1d4de3c1219b28d408aa807a6a23d2427c7a1aa3f2b094
@@ -11,6 +11,10 @@ module Replay
11
11
  @event.type
12
12
  end
13
13
 
14
+ def explode
15
+ return @stream_id, @event, @metadata
16
+ end
17
+
14
18
  def method_missing(method, *args)
15
19
  return @event.send(method, args) if @event.respond_to?(method)
16
20
  super
@@ -12,18 +12,42 @@ module Replay
12
12
  @router = rtr
13
13
  end
14
14
 
15
+ #gives the observer a chance to take itself down to a null state
16
+ #in the event of a catchup
17
+ #must be overridden in the base class
18
+ def reset!
19
+ raise "reset must be implemented in the observing class"
20
+ end
21
+
15
22
  def observe(event_type, &block)
16
23
  raise InvalidRouterError.new("No router defined!") unless @router
24
+ @observed_events ||= Set.new
25
+ @observed_events.add(event_type)
26
+
17
27
  @observer_blocks ||= Hash.new
18
28
  @observer_blocks[Replay::Inflector.underscore(event_type.to_s)] = block
19
29
 
20
30
  @router.add_observer self, event_type
21
31
  end
22
32
 
23
- def published(stream_id, event)
24
- blk = @observer_blocks[Replay::Inflector.underscore(event.type)]
25
- blk.call(stream_id, event, binding) if blk
33
+ def observed_events
34
+ @observed_events.dup
35
+ end
36
+
37
+ def handle(stream_id, event)
38
+ published(stream_id, event)
26
39
  end
40
+
41
+ def published(stream_id, envelope)
42
+ blk = @observer_blocks[Replay::Inflector.underscore(envelope.type)]
43
+ blk.call(stream_id, envelope, binding) if blk
44
+ end
45
+
46
+ private
47
+ def handler_method(event_type)
48
+ "handle_#{Replay::Inflector.underscore(event_type.to_s).gsub(".", "_")}"
49
+ end
50
+
27
51
  end
28
52
  end
29
53
  end
@@ -48,3 +48,9 @@ RSpec::Matchers.define :publish do |expected_event|
48
48
 
49
49
  end
50
50
 
51
+ RSpec::Matchers.define :observes do |event_class|
52
+ match do |observer|
53
+ observer.observes?(event_class)
54
+ end
55
+ end
56
+
@@ -18,7 +18,7 @@ module Replay
18
18
  @subscribers.each do |sub|
19
19
  begin
20
20
  meta = metadata.merge(@session_metadata || {})
21
- sub.published(EventEnvelope.new(stream_id, event, meta))
21
+ sub.published(EventEnvelope.new(stream_id, event.dup, meta))
22
22
  #sub.published(stream_id, event, metadata)
23
23
  rescue Exception => e
24
24
  #hmmmm
@@ -31,6 +31,12 @@ module Replay::EventExaminer
31
31
  end
32
32
  end
33
33
 
34
+ Replay::Observer.module_exec do
35
+ def observes?(event_class)
36
+ @observer_blocks.has_key?(Replay::Inflector.underscore(event_class.to_s))
37
+ end
38
+ end
39
+
34
40
  Replay::SubscriptionManager.class_exec do
35
41
  def has_subscriber?(subscriber)
36
42
  @subscribers.include?(subscriber)
@@ -1,3 +1,3 @@
1
1
  module Replay
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -0,0 +1,35 @@
1
+ require_relative "../proofs_init.rb"
2
+ require 'replay/test'
3
+
4
+ class ThingEvent
5
+ include Replay::EventDecorator
6
+ attribute :foo, String
7
+ end
8
+ class ThingObserver
9
+ include Replay::Observer
10
+
11
+ def self.foo
12
+ @foo ||= ''
13
+ end
14
+ observe ThingEvent do |stream_id, event|
15
+ @foo ||= 'foo'
16
+ @foo = event.foo
17
+ end
18
+ end
19
+
20
+ module ThingObserver::Proof
21
+
22
+ end
23
+ title "Thing observer"
24
+ proof "Thing observer does its thing" do
25
+ ThingObserver.prove do
26
+ ThingObserver.handle('123', ThingEvent.new(:foo => "boo"))
27
+ ThingObserver.foo == "boo"
28
+ end
29
+ end
30
+
31
+ proof "observers have observed events" do
32
+ ThingObserver.prove{ ThingObserver.observed_events.include?(ThingEvent)}
33
+ end
34
+
35
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - karmajunkie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,6 +104,7 @@ files:
104
104
  - proofs/all.rb
105
105
  - proofs/proofs_init.rb
106
106
  - proofs/replay/inflector_proof.rb
107
+ - proofs/replay/observer_proof.rb
107
108
  - proofs/replay/publisher_proof.rb
108
109
  - proofs/replay/repository_configuration_proof.rb
109
110
  - proofs/replay/repository_proof.rb