reactor 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/reactor/event.rb +7 -2
- data/lib/reactor/models/concerns/subscribable.rb +9 -2
- data/lib/reactor/version.rb +1 -1
- data/lib/reactor.rb +1 -1
- data/spec/models/concerns/subscribable_spec.rb +18 -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: 0f1aac22b0919076019fe2d53dd7999309d25216
|
4
|
+
data.tar.gz: 0ea239c9e18da1b510ff0ef87971abc991425b9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ef2dabe5ccedc03b97990c583a992c6145716cd775d90fada6540a4b9395195e677db3e135d159240830be6701871a5615cbe966f769e3a4568b936bf925168
|
7
|
+
data.tar.gz: 81f0d2605e65e50f3df59b2fe79f29e6ff327e8c658e6d9d6c6ee3e39bed8a0fbdb775551a33b7e888e68cd5efc21e6c44a32943eba30acf593bafc120a83d8a
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ Well, this is evolving, so it's probably best to go read the specs.
|
|
48
48
|
|
49
49
|
You can now bind any block to an event in your models like so
|
50
50
|
|
51
|
-
|
51
|
+
on_event :any_event do |event|
|
52
52
|
MyModel.find(event.target).do_something_about_it!
|
53
53
|
end
|
54
54
|
|
data/lib/reactor/event.rb
CHANGED
@@ -56,9 +56,14 @@ class Reactor::Event
|
|
56
56
|
Reactor::Subscriber.delay.fire s.id, data
|
57
57
|
end
|
58
58
|
|
59
|
-
if (static_subscribers = Reactor::
|
59
|
+
if (static_subscribers = Reactor::SUBSCRIBERS[name.to_s] || []).any?
|
60
60
|
static_subscribers.each do |callback|
|
61
|
-
callback
|
61
|
+
case callback
|
62
|
+
when Hash
|
63
|
+
callback.keys.first.send callback.values.first, Reactor::Event.new(data.merge(event: name.to_s))
|
64
|
+
else
|
65
|
+
callback.call Reactor::Event.new(data.merge(event: name.to_s))
|
66
|
+
end
|
62
67
|
end
|
63
68
|
end
|
64
69
|
end
|
@@ -2,8 +2,15 @@ module Reactor::Subscribable
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
module ClassMethods
|
5
|
-
def on_event(event, &
|
6
|
-
|
5
|
+
def on_event(event, method = nil, &block)
|
6
|
+
callback = case method
|
7
|
+
when Symbol
|
8
|
+
{self => method}
|
9
|
+
else
|
10
|
+
method
|
11
|
+
end
|
12
|
+
callback = block if block
|
13
|
+
(Reactor::SUBSCRIBERS[event.to_s] ||= []).push(callback)
|
7
14
|
end
|
8
15
|
end
|
9
16
|
end
|
data/lib/reactor/version.rb
CHANGED
data/lib/reactor.rb
CHANGED
@@ -5,14 +5,31 @@ class Auction < ActiveRecord::Base
|
|
5
5
|
on_event :bid_made do |event|
|
6
6
|
event.target.update_column :status, 'first_bid_made'
|
7
7
|
end
|
8
|
+
|
9
|
+
on_event :puppy_delivered, :ring_bell
|
10
|
+
on_event :any_event, -> (event) { puppies! }
|
11
|
+
|
12
|
+
def self.ring_bell(event)
|
13
|
+
pp "ring ring! #{event}"
|
14
|
+
end
|
8
15
|
end
|
9
16
|
|
10
17
|
describe Reactor::Subscribable do
|
11
18
|
|
12
|
-
describe '
|
19
|
+
describe 'on_event' do
|
13
20
|
it 'binds block of code statically to event being fired' do
|
14
21
|
Auction.any_instance.should_receive(:update_column).with(:status, 'first_bid_made')
|
15
22
|
Reactor::Event.publish(:bid_made, target: Auction.create)
|
16
23
|
end
|
24
|
+
|
25
|
+
it 'binds symbol to class method' do
|
26
|
+
Auction.should_receive(:ring_bell)
|
27
|
+
Reactor::Event.publish(:puppy_delivered)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'binds proc' do
|
31
|
+
Auction.should_receive(:puppies!)
|
32
|
+
Reactor::Event.publish(:any_event)
|
33
|
+
end
|
17
34
|
end
|
18
35
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winfred
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|