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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98effb7058e42105083b6140ae324fa6bbc09c15
4
- data.tar.gz: 2d869d077ad24edaf0ca70d6afa35eab454d549b
3
+ metadata.gz: 5e63dbb0bcf3a8396d130eeb955538359cd9551d
4
+ data.tar.gz: 704feccc84221143a8b90f7a86d139f7b6e91682
5
5
  SHA512:
6
- metadata.gz: 480067daea1832ef2dd8f06f011e45cac9c75e2662e69dacf0afb2149286fe853000f50310e18461b5c18261b19487cbf435efb25497089d2f18a61c0f2ab11d
7
- data.tar.gz: 10f4c872fe0ec5898f0b7c34e5d36bb51735b1ef7229b8f7dd23a26cb8f2f1851e356e6c7b25e2ed55a52226410b7a9cecefa191bb24c7ad09815dbb4a14f149
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
- delay_until(message.at).process name, message.data
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
- if data[:at] && send("#{data[:watch] || data[:at]}_changed?")
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
@@ -1,3 +1,3 @@
1
1
  module Reactor
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -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.5
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-03 00:00:00.000000000 Z
12
+ date: 2013-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler