reactor 0.1.0 → 0.1.1
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 +1 -0
- data/lib/reactor/models/concerns/eventable.rb +6 -5
- data/lib/reactor/version.rb +1 -1
- data/spec/models/concerns/eventable_spec.rb +31 -4
- data/spec/models/subscriber_spec.rb +0 -30
- data/spec/spec_helper.rb +1 -0
- 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: 3f30c15c4574595a8879b7dd9a6058605dad0ad1
|
4
|
+
data.tar.gz: 14ae0caff4f4487d87be51e55e0408811ca7f576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74d22941c9ead4ab5ec852d77f9ffce49c0045947a9ed993cfabf4ab47b98ff225db226566458faa74f6c4ea73071aec62c10eb24f1724835cae4dd87b7f50a5
|
7
|
+
data.tar.gz: 90e8a390c1128c75e3bb93bd35e47c1b16e3d784bb540f59a9c5b787318058aba0d592cf6c34174360fba11d6db74665c0966cfa8c8c993d9116a997ef9e7a34
|
data/lib/reactor/event.rb
CHANGED
@@ -2,8 +2,8 @@ module Reactor::Eventable
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
|
-
|
6
|
-
|
5
|
+
after_commit :schedule_events, if: :persisted?, on: :create
|
6
|
+
after_commit :reschedule_events, if: :persisted?, on: :update
|
7
7
|
end
|
8
8
|
|
9
9
|
def publish(name, data = {})
|
@@ -24,15 +24,16 @@ module Reactor::Eventable
|
|
24
24
|
|
25
25
|
def schedule_events
|
26
26
|
self.class.events.each do |name, data|
|
27
|
-
|
28
|
-
|
27
|
+
data = data.merge(
|
28
|
+
at: ( data[:at] ? send(data[:at]) : nil), actor: self
|
29
29
|
).except(:watch)
|
30
|
+
Reactor::Event.delay.publish name, data
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
def reschedule_events
|
34
35
|
self.class.events.each do |name, data|
|
35
|
-
if send("#{data[:watch] || data[:at]}_changed?")
|
36
|
+
if data[:at] && send("#{data[:watch] || data[:at]}_changed?")
|
36
37
|
Reactor::Event.delay.reschedule name,
|
37
38
|
at: send(data[:at]),
|
38
39
|
actor: self,
|
data/lib/reactor/version.rb
CHANGED
@@ -1,20 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class Auction < ActiveRecord::Base
|
4
|
-
def ring_timeout
|
5
|
-
created_at +
|
4
|
+
def ring_timeout
|
5
|
+
created_at + 30.seconds
|
6
6
|
end
|
7
7
|
|
8
|
+
def ring_timeout_was
|
9
|
+
created_at + 10.seconds
|
10
|
+
end
|
11
|
+
|
12
|
+
publishes :bell
|
8
13
|
publishes :ring, at: :ring_timeout, watch: :name
|
9
14
|
end
|
10
15
|
|
16
|
+
class TestSubscriber < Reactor::Subscriber
|
17
|
+
|
18
|
+
on_fire do
|
19
|
+
@@called = true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
describe Reactor::Eventable do
|
12
24
|
describe 'publish' do
|
13
|
-
let(:auction) { Auction.create }
|
25
|
+
let(:auction) { Auction.create! }
|
14
26
|
|
15
27
|
it 'publishes an event with actor_id and actor_type set as self' do
|
16
|
-
|
28
|
+
auction
|
29
|
+
Reactor::Event.should_receive(:publish) do |name, data|
|
30
|
+
name.should == :an_event
|
31
|
+
data[:what].should == 'the'
|
32
|
+
data[:actor].should == auction
|
33
|
+
end
|
17
34
|
auction.publish(:an_event, {what: 'the'})
|
18
35
|
end
|
36
|
+
|
37
|
+
it 'supports immediate events (on create) that get fired once' do
|
38
|
+
TestSubscriber.create! event: :bell
|
39
|
+
auction
|
40
|
+
TestSubscriber.class_variable_get(:@@called).should be_true
|
41
|
+
TestSubscriber.class_variable_set(:@@called, false)
|
42
|
+
auction.start_at = 1.day.from_now
|
43
|
+
auction.save
|
44
|
+
TestSubscriber.class_variable_get(:@@called).should be_false
|
45
|
+
end
|
19
46
|
end
|
20
47
|
end
|
@@ -22,36 +22,6 @@ describe Reactor::Subscriber do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '.subscribes_to class helper' do
|
25
|
-
#describe 'ensuring subscriber exists and is tied to event' do
|
26
|
-
# it 'binds 1-1 when name given' do
|
27
|
-
# expect {
|
28
|
-
# MySubscriber.class_eval do
|
29
|
-
# subscribes_to :event_times
|
30
|
-
# end
|
31
|
-
# }.to change { Reactor::Subscriber.count }.by(1)
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# context 'binds to all when star is given' do
|
35
|
-
# after { MySubscriber.destroy_all }
|
36
|
-
#
|
37
|
-
# it 'creates new subscriber' do
|
38
|
-
# expect {
|
39
|
-
# MySubscriber.class_eval do
|
40
|
-
# subscribes_to '*'
|
41
|
-
# end
|
42
|
-
# }.to change { Reactor::Subscriber.count }.by(1)
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
# it 'doesnt create' do
|
46
|
-
# MySubscriber.where(event: '*').first_or_create!
|
47
|
-
# expect {
|
48
|
-
# MySubscriber.class_eval do
|
49
|
-
# subscribes_to '*'
|
50
|
-
# end
|
51
|
-
# }.to change { Reactor::Subscriber.count }.by(0)
|
52
|
-
# end
|
53
|
-
# end
|
54
|
-
#end
|
55
25
|
end
|
56
26
|
|
57
27
|
describe 'matcher' do
|
data/spec/spec_helper.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
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-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|