entity_store 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/entity_store/event_bus.rb +15 -8
- data/lib/entity_store/version.rb +1 -1
- data/spec/entity_store/event_bus_spec.rb +14 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1ceade888f0ca9a1807f1d103cd9b49f34d1246
|
4
|
+
data.tar.gz: 0be6cae4eb7ab32f4e2cde36c4f3028ed42fa068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f564aadd920f1fd2424178f15e04ceba311d59c2e6a2a41ecc229004b8244dfeb2facd86edc2ddf0273d1c7f7c375a394a6f64e15b9ebec56ebe0617de45440e
|
7
|
+
data.tar.gz: fb8885e4a843368e936271aa638de38d754aa24cffa584e1e8674625a6ce659f5132aaae6f1d9a2ea7cd29b105133cb1d1d65894fa66bba774b8d1cc6e5514bf
|
@@ -2,23 +2,30 @@ module EntityStore
|
|
2
2
|
class EventBus
|
3
3
|
include Logging
|
4
4
|
|
5
|
+
ALL_METHOD = :all_events
|
6
|
+
|
5
7
|
def publish(entity_type, event)
|
6
8
|
publish_to_feed entity_type, event
|
7
9
|
|
8
|
-
subscribers_to(event.receiver_name).each do |s|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
subscribers_to(event.receiver_name).each do |s| send_to_subscriber s, event.receiver_name, event end
|
11
|
+
subscribers_to_all.each do |s| send_to_subscriber s, ALL_METHOD, event end
|
12
|
+
end
|
13
|
+
|
14
|
+
def send_to_subscriber subscriber, receiver_name, event
|
15
|
+
subscriber.new.send(receiver_name, event)
|
16
|
+
log_debug { "called #{subscriber.name}##{receiver_name} with #{event.inspect}" }
|
17
|
+
rescue => e
|
18
|
+
log_error "#{e.message} when calling #{subscriber.name}##{receiver_name} with #{event.inspect}", e
|
16
19
|
end
|
17
20
|
|
18
21
|
def subscribers_to(event_name)
|
19
22
|
subscribers.select { |s| s.instance_methods.include?(event_name.to_sym) }
|
20
23
|
end
|
21
24
|
|
25
|
+
def subscribers_to_all
|
26
|
+
subscribers.select { |s| s.instance_methods.include?(ALL_METHOD) }
|
27
|
+
end
|
28
|
+
|
22
29
|
def subscribers
|
23
30
|
EntityStore::Config.event_subscribers
|
24
31
|
end
|
data/lib/entity_store/version.rb
CHANGED
@@ -11,6 +11,12 @@ class DummySubscriber
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
class DummyAllSubscriber
|
15
|
+
def all_events
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
describe EventBus do
|
15
21
|
before(:each) do
|
16
22
|
@entity_type = random_string
|
@@ -19,10 +25,12 @@ describe EventBus do
|
|
19
25
|
end
|
20
26
|
describe ".publish" do
|
21
27
|
before(:each) do
|
22
|
-
@subscriber =
|
28
|
+
@subscriber = DummySubscriber.new
|
23
29
|
DummySubscriber.stub(:new) { @subscriber }
|
24
30
|
@subscriber_class2 = mock("SubscriberClass", :instance_methods => ['bilge'], :name => "SubscriberClass")
|
25
|
-
@
|
31
|
+
@all_subscriber = DummyAllSubscriber.new
|
32
|
+
DummyAllSubscriber.stub(:new) { @all_subscriber }
|
33
|
+
@event_bus.stub(:subscribers).and_return([DummySubscriber, @subscriber_class2, DummyAllSubscriber])
|
26
34
|
@event_bus.stub(:publish_to_feed)
|
27
35
|
end
|
28
36
|
|
@@ -36,6 +44,10 @@ describe EventBus do
|
|
36
44
|
@subscriber_class2.should_not_receive(:new)
|
37
45
|
subject
|
38
46
|
end
|
47
|
+
it "should call the all method of the all subscriber" do
|
48
|
+
@all_subscriber.should_receive(:all_events).with(@event)
|
49
|
+
subject
|
50
|
+
end
|
39
51
|
it "publishes event to the external event push" do
|
40
52
|
@event_bus.should_receive(:publish_to_feed).with(@entity_type, @event)
|
41
53
|
subject
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entity_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Bird
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.1.2
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Event sourced entity store with a replaceable body
|
@@ -119,3 +119,4 @@ test_files:
|
|
119
119
|
- spec/entity_store/store_spec.rb
|
120
120
|
- spec/entity_store_spec.rb
|
121
121
|
- spec/spec_helper.rb
|
122
|
+
has_rdoc:
|