reactor 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b2acc2924cce460d8ecbf94f1ae6a4a52378505
|
4
|
+
data.tar.gz: 50cbd56f3d0365152a30dc4d87d33f32b422438e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adcff3f313dcdf7a1d6b2e83496c69e46ca9f83124c454d826047c389236adb7dd54dc4b04e8fd376616429ecaba00e13c315123d1f8b2d133e44bc999bed641
|
7
|
+
data.tar.gz: d88e4755294c7e6a5b2fcec2831e6e6cbbd24a39bc4d72cb85dbba4c36990a7f8a7f62f2d5a668c315636d727c1fb031b3e249c707c2fcac1045d481e18b62fd
|
@@ -25,7 +25,9 @@ module Reactor::Eventable
|
|
25
25
|
def schedule_events
|
26
26
|
self.class.events.each do |name, data|
|
27
27
|
event = data.merge(
|
28
|
-
|
28
|
+
actor: ( data[:actor] ? send(data[:actor]) : self ),
|
29
|
+
target: ( data[:target] ? send(data[:target]) : nil),
|
30
|
+
at: ( data[:at] ? send(data[:at]) : nil)
|
29
31
|
).except(:watch, :if)
|
30
32
|
need_to_fire = case (ifarg = data[:if])
|
31
33
|
when Proc
|
@@ -44,7 +46,8 @@ module Reactor::Eventable
|
|
44
46
|
if data[:at] && send("#{data[:watch] || data[:at]}_changed?")
|
45
47
|
Reactor::Event.delay.reschedule name,
|
46
48
|
at: send(data[:at]),
|
47
|
-
actor: self,
|
49
|
+
actor: ( data[:actor] ? send(data[:actor]) : self ),
|
50
|
+
target: ( data[:target] ? send(data[:target]) : nil),
|
48
51
|
was: send("#{data[:at]}_was")
|
49
52
|
end
|
50
53
|
|
data/lib/reactor/version.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class Pet < ActiveRecord::Base
|
4
|
+
end
|
5
|
+
|
3
6
|
class Auction < ActiveRecord::Base
|
4
7
|
attr_accessor :we_want_it
|
8
|
+
belongs_to :pet
|
5
9
|
|
6
10
|
def ring_timeout
|
7
11
|
created_at + 30.seconds
|
@@ -14,6 +18,7 @@ class Auction < ActiveRecord::Base
|
|
14
18
|
publishes :bell
|
15
19
|
publishes :ring, at: :ring_timeout, watch: :name
|
16
20
|
publishes :conditional_event_on_save, if: -> { we_want_it }
|
21
|
+
publishes :woof, actor: :pet, target: :self
|
17
22
|
end
|
18
23
|
|
19
24
|
class TestSubscriber < Reactor::Subscriber
|
@@ -26,7 +31,8 @@ end
|
|
26
31
|
|
27
32
|
describe Reactor::Eventable do
|
28
33
|
describe 'publish' do
|
29
|
-
let(:
|
34
|
+
let(:pet) { Pet.create! }
|
35
|
+
let(:auction) { Auction.create!(pet: pet) }
|
30
36
|
|
31
37
|
it 'publishes an event with actor_id and actor_type set as self' do
|
32
38
|
auction
|
@@ -38,6 +44,14 @@ describe Reactor::Eventable do
|
|
38
44
|
auction.publish(:an_event, {what: 'the'})
|
39
45
|
end
|
40
46
|
|
47
|
+
it 'publishes an event with provided actor and target methods' do
|
48
|
+
Reactor::Event.should_receive(:publish) do |name, data|
|
49
|
+
name.should == :woof
|
50
|
+
data[:actor].should == pet
|
51
|
+
end
|
52
|
+
auction
|
53
|
+
end
|
54
|
+
|
41
55
|
it 'supports immediate events (on create) that get fired once' do
|
42
56
|
TestSubscriber.create! event: :bell
|
43
57
|
auction
|
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.2.0
|
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-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|