reactor 0.2.5 → 0.2.6
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/reactor/event.rb +9 -3
- data/lib/reactor/models/concerns/eventable.rb +2 -2
- data/lib/reactor/version.rb +1 -1
- data/spec/models/concerns/eventable_spec.rb +17 -2
- 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: 5e63dbb0bcf3a8396d130eeb955538359cd9551d
|
4
|
+
data.tar.gz: 704feccc84221143a8b90f7a86d139f7b6e91682
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a68f0f4b9cdb3bf696b66538f1a3dbc0cca8f840d8b2de18cabb7e904b0539efaa4caffdbbef46cf44cc0fe81c7996122eec0005268a7f943b1df334e54a855e
|
7
|
+
data.tar.gz: 0d3ba40af3fb198544d7b7d150a8c3b1ee312af095b304dd3e334c56ebad0b6915326d2ed881be0fbed4fc3c5eea08ea7985e239b54419bed136f69be6ecc512
|
data/lib/reactor/event.rb
CHANGED
@@ -24,10 +24,16 @@ class Reactor::Event
|
|
24
24
|
|
25
25
|
def self.publish(name, data = {})
|
26
26
|
message = new(data.merge(event: name))
|
27
|
-
if (message.at)
|
28
|
-
|
29
|
-
else
|
27
|
+
#if (message.at)
|
28
|
+
# delay_until(message.at).process name, message.data
|
29
|
+
#else
|
30
|
+
# delay.process name, message.data
|
31
|
+
#end
|
32
|
+
|
33
|
+
if message.at.nil?
|
30
34
|
delay.process name, message.data
|
35
|
+
elsif message.at.future?
|
36
|
+
delay_until(message.at).process name, message.data
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
@@ -43,14 +43,14 @@ module Reactor::Eventable
|
|
43
43
|
|
44
44
|
def reschedule_events
|
45
45
|
self.class.events.each do |name, data|
|
46
|
-
|
46
|
+
attr_changed_method = "#{data[:watch] || data[:at]}_changed?"
|
47
|
+
if data[:at] && respond_to?(attr_changed_method) && send(attr_changed_method)
|
47
48
|
Reactor::Event.delay.reschedule name,
|
48
49
|
at: send(data[:at]),
|
49
50
|
actor: ( data[:actor] ? send(data[:actor]) : self ),
|
50
51
|
target: ( data[:target] ? self : nil),
|
51
52
|
was: send("#{data[:at]}_was")
|
52
53
|
end
|
53
|
-
|
54
54
|
if data[:if]
|
55
55
|
need_to_fire = case (ifarg = data[:if])
|
56
56
|
when Proc
|
data/lib/reactor/version.rb
CHANGED
@@ -4,7 +4,7 @@ class Pet < ActiveRecord::Base
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class Auction < ActiveRecord::Base
|
7
|
-
attr_accessor :we_want_it
|
7
|
+
attr_accessor :we_want_it, :arbitrary_date
|
8
8
|
belongs_to :pet
|
9
9
|
|
10
10
|
def ring_timeout
|
@@ -17,6 +17,7 @@ class Auction < ActiveRecord::Base
|
|
17
17
|
|
18
18
|
publishes :bell
|
19
19
|
publishes :ring, at: :ring_timeout, watch: :name
|
20
|
+
publishes :begin, at: :arbitrary_date
|
20
21
|
publishes :conditional_event_on_save, if: -> { we_want_it }
|
21
22
|
publishes :woof, actor: :pet, target: :self
|
22
23
|
end
|
@@ -30,9 +31,10 @@ class TestSubscriber < Reactor::Subscriber
|
|
30
31
|
end
|
31
32
|
|
32
33
|
describe Reactor::Eventable do
|
34
|
+
before { TestSubscriber.destroy_all }
|
33
35
|
describe 'publish' do
|
34
36
|
let(:pet) { Pet.create! }
|
35
|
-
let(:auction) { Auction.create!(pet: pet) }
|
37
|
+
let(:auction) { Auction.create!(pet: pet, arbitrary_date: DateTime.new(2012,12,21)) }
|
36
38
|
|
37
39
|
it 'publishes an event with actor_id and actor_type set as self' do
|
38
40
|
auction
|
@@ -62,6 +64,18 @@ describe Reactor::Eventable do
|
|
62
64
|
TestSubscriber.class_variable_get(:@@called).should be_false
|
63
65
|
end
|
64
66
|
|
67
|
+
it 'does not publish an event scheduled for the past' do
|
68
|
+
TestSubscriber.create! event: :begin
|
69
|
+
auction
|
70
|
+
TestSubscriber.class_variable_get(:@@called).should be_false
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does publish an event scheduled for the future' do
|
74
|
+
TestSubscriber.create! event: :begin
|
75
|
+
Auction.create!(pet: pet, arbitrary_date: Time.current + 1.week)
|
76
|
+
TestSubscriber.class_variable_get(:@@called).should be_true
|
77
|
+
end
|
78
|
+
|
65
79
|
it 'can fire events onsave for any condition' do
|
66
80
|
TestSubscriber.create! event: :conditional_event_on_save
|
67
81
|
auction
|
@@ -69,6 +83,7 @@ describe Reactor::Eventable do
|
|
69
83
|
auction.start_at = 1.day.from_now
|
70
84
|
auction.save
|
71
85
|
TestSubscriber.class_variable_get(:@@called).should be_false
|
86
|
+
auction.start_at = 2.days.from_now
|
72
87
|
auction.we_want_it = true
|
73
88
|
auction.save
|
74
89
|
TestSubscriber.class_variable_get(:@@called).should be_true
|
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.2.
|
4
|
+
version: 0.2.6
|
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-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|