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 +4 -4
- data/lib/replay/event_envelope.rb +4 -0
- data/lib/replay/observer.rb +27 -3
- data/lib/replay/rspec.rb +6 -0
- data/lib/replay/subscription_manager.rb +1 -1
- data/lib/replay/test.rb +6 -0
- data/lib/replay/version.rb +1 -1
- data/proofs/replay/observer_proof.rb +35 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc1383b965327df0adcc628798ba7aa1bced6a77
|
4
|
+
data.tar.gz: 0f356feb134a03df3451c63a725c83a7e70de7b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a12609875ef5e36b0a39f20eba5c481f5eb5c5d06d912b66c517cbd91bcbbdf7b63e9afc4437f1ee48c1a6719a582bf49f65ee0179fbe1cf6ffc7dc5e899b00e
|
7
|
+
data.tar.gz: 09d59773b29803f51d614fc7bff2bb45d65f063b9967490191015682a1d63a6c0724136d12a3b1661c1d4de3c1219b28d408aa807a6a23d2427c7a1aa3f2b094
|
data/lib/replay/observer.rb
CHANGED
@@ -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
|
24
|
-
|
25
|
-
|
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
|
data/lib/replay/rspec.rb
CHANGED
@@ -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
|
data/lib/replay/test.rb
CHANGED
@@ -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)
|
data/lib/replay/version.rb
CHANGED
@@ -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.
|
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-
|
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
|