event_bus 0.1.0 → 0.1.1
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.
- data/Gemfile.lock +1 -1
- data/lib/event_bus.rb +1 -1
- data/spec/lib/event_bus_spec.rb +15 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/event_bus.rb
CHANGED
@@ -56,7 +56,7 @@ class EventBus
|
|
56
56
|
#
|
57
57
|
def subscribe(pattern, listener = nil, method_name = nil, &blk)
|
58
58
|
case pattern
|
59
|
-
when Regexp, String
|
59
|
+
when Regexp, String, Symbol
|
60
60
|
subscribe_pattern(pattern, listener, method_name, &blk)
|
61
61
|
else
|
62
62
|
raise ArgumentError.new('You cannot give two listeners') if listener || method_name
|
data/spec/lib/event_bus_spec.rb
CHANGED
@@ -80,6 +80,21 @@ describe EventBus do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
context 'with a symbol pattern' do
|
84
|
+
it 'sends the event to a matching listener' do
|
85
|
+
event_name = :abc_123
|
86
|
+
EventBus.subscribe(event_name, listener, receiving_method)
|
87
|
+
listener.should_receive(receiving_method).with(a: 1, b: 2, event_name: event_name)
|
88
|
+
EventBus.publish(event_name, a: 1, b: 2)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'does not send the event to non-matching listeners' do
|
92
|
+
EventBus.subscribe(:blah, listener, receiving_method)
|
93
|
+
listener.should_not_receive(receiving_method)
|
94
|
+
EventBus.publish(event_name, a: 1, b: 2, event_name: event_name)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
83
98
|
context 'with a listener method' do
|
84
99
|
it 'will not accept a block too' do
|
85
100
|
expect { EventBus.subscribe('blah', listener, receiving_method) {|info| }}.to raise_error(ArgumentError)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|