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: 0856dd83dd99bfe7c3d6ee5f3fa873a2d877bf93
4
- data.tar.gz: 3642465ade68d3b77c018fe5527ce0826b222e24
3
+ metadata.gz: 6b2acc2924cce460d8ecbf94f1ae6a4a52378505
4
+ data.tar.gz: 50cbd56f3d0365152a30dc4d87d33f32b422438e
5
5
  SHA512:
6
- metadata.gz: 6848ba780655780d5f013d20e179ef41a6b04d89efb52d2fda2b0612ce2d507db2c0b4fe5f4b79f7103fb60a724ef984e3fa548791d1ae05ad1814e352d80c27
7
- data.tar.gz: 9306a61c4bbc432cf4e1f88bf767f057ca8f16b0dd194f0de6bbdc39636bc5bfd3a9b951aa412c6feddab38ce96c3dddf4a039bfe60d5368592dd0b221675314
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
- at: ( data[:at] ? send(data[:at]) : nil), actor: self
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
 
@@ -1,3 +1,3 @@
1
1
  module Reactor
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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(:auction) { Auction.create! }
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
@@ -8,6 +8,7 @@ ActiveRecord::Migration.create_table :auctions do |t|
8
8
  t.string :name
9
9
  t.datetime :start_at
10
10
  t.datetime :close_at
11
+ t.integer :pet_id
11
12
 
12
13
  t.timestamps
13
14
  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.1.4
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-02 00:00:00.000000000 Z
12
+ date: 2013-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler