reactor 0.4.7 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reactor/event.rb +5 -4
- data/lib/reactor/version.rb +1 -1
- data/spec/event_spec.rb +1 -1
- data/spec/models/concerns/subscribable_spec.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11693bb99d91dfe0e19245876a0367c7580563a6
|
4
|
+
data.tar.gz: c3c2957d48171f38bf6673e1b55a5ec95977ed00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b002c8547c7e0893c9e45b58d14254364b6bf141f32725f7bb822c0766ab8c054a3a9b7ac3bcf61435cd03c9b396db07ea1088875d3c4a9b3bc8d0ee69db7f77
|
7
|
+
data.tar.gz: c294f5349ce9c2d4b28e789a1059dc3c1a71c6682f5b91b739284052a1634bb496a5c2ab0808acc318b21d662b946a75875c2b2fa10b0b242b64331c347e838a
|
data/lib/reactor/event.rb
CHANGED
@@ -12,7 +12,7 @@ class Reactor::Event
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def perform(name, data)
|
15
|
-
data.merge!(fired_at: Time.current)
|
15
|
+
data.merge!(fired_at: Time.current, name: name)
|
16
16
|
Reactor::Subscriber.where(event: name).each do |subscriber|
|
17
17
|
Reactor::Subscriber.delay.fire subscriber.id, data
|
18
18
|
end
|
@@ -22,14 +22,15 @@ class Reactor::Event
|
|
22
22
|
Reactor::Subscriber.delay.fire s.id, data
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
static_subscribers = (Reactor::SUBSCRIBERS[name.to_s] || []) | (Reactor::SUBSCRIBERS['*'] || [])
|
26
|
+
if static_subscribers.any?
|
26
27
|
static_subscribers.each do |callback|
|
27
28
|
delay = callback[:options].try(:[], :delay) || 0
|
28
29
|
case method = callback[:method]
|
29
30
|
when Symbol
|
30
|
-
callback[:source].delay_for(delay).send method, Reactor::Event.new(data
|
31
|
+
callback[:source].delay_for(delay).send method, Reactor::Event.new(data)
|
31
32
|
else
|
32
|
-
method.call Reactor::Event.new(data
|
33
|
+
method.call Reactor::Event.new(data)
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
data/lib/reactor/version.rb
CHANGED
data/spec/event_spec.rb
CHANGED
@@ -38,7 +38,7 @@ describe Reactor::Event do
|
|
38
38
|
|
39
39
|
it 'works with the legacy .process method, too' do
|
40
40
|
Reactor::Subscriber.any_instance.should_receive(:fire).with(hash_including(actor_id: '1'))
|
41
|
-
Reactor::Event.
|
41
|
+
Reactor::Event.perform(event_name, actor_id: '1')
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -9,6 +9,9 @@ class Auction < ActiveRecord::Base
|
|
9
9
|
on_event :puppy_delivered, :ring_bell
|
10
10
|
on_event :any_event, -> (event) { puppies! }
|
11
11
|
on_event :pooped, :pick_up_poop, delay: 5.minutes
|
12
|
+
on_event '*' do |event|
|
13
|
+
event.actor.more_puppies! if event.name == 'another_event'
|
14
|
+
end
|
12
15
|
|
13
16
|
def self.ring_bell(event)
|
14
17
|
pp "ring ring! #{event}"
|
@@ -42,5 +45,10 @@ describe Reactor::Subscribable do
|
|
42
45
|
Auction.should_receive(:puppies!)
|
43
46
|
Reactor::Event.publish(:any_event)
|
44
47
|
end
|
48
|
+
|
49
|
+
it 'accepts wildcard event name' do
|
50
|
+
Auction.any_instance.should_receive(:more_puppies!)
|
51
|
+
Reactor::Event.publish(:another_event, actor: Auction.create)
|
52
|
+
end
|
45
53
|
end
|
46
|
-
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winfred
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-08-
|
15
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: sidekiq
|