reactor 0.4.7 → 0.5.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: 5ace8ce445f2aebac77523482a0a16112cda5143
4
- data.tar.gz: 1844c28133029e8b9ed6d1eac32793efd2a58ede
3
+ metadata.gz: 11693bb99d91dfe0e19245876a0367c7580563a6
4
+ data.tar.gz: c3c2957d48171f38bf6673e1b55a5ec95977ed00
5
5
  SHA512:
6
- metadata.gz: d268ec515c2b5e26577ebac12299a4969de3a17721e8dd02d9509b0b10cc8010115331d55ca3a8b133e7e51de619b30a1e4ccea9cc3f915c3ed7237ee60f998d
7
- data.tar.gz: d0c4f6f3d2b99293034ffb76f06b48a34ed7a4b23a917801706478d390ea115a9a6f827ef843f3cbc8dd8ea1ea1b2ab0a9ab4984d9f81b08c5f13c341a656f38
6
+ metadata.gz: b002c8547c7e0893c9e45b58d14254364b6bf141f32725f7bb822c0766ab8c054a3a9b7ac3bcf61435cd03c9b396db07ea1088875d3c4a9b3bc8d0ee69db7f77
7
+ data.tar.gz: c294f5349ce9c2d4b28e789a1059dc3c1a71c6682f5b91b739284052a1634bb496a5c2ab0808acc318b21d662b946a75875c2b2fa10b0b242b64331c347e838a
data/lib/reactor/event.rb CHANGED
@@ -12,7 +12,7 @@ class Reactor::Event
12
12
  end
13
13
 
14
14
  def perform(name, data)
15
- data.merge!(fired_at: Time.current)
15
+ data.merge!(fired_at: Time.current, name: name)
16
16
  Reactor::Subscriber.where(event: name).each do |subscriber|
17
17
  Reactor::Subscriber.delay.fire subscriber.id, data
18
18
  end
@@ -22,14 +22,15 @@ class Reactor::Event
22
22
  Reactor::Subscriber.delay.fire s.id, data
23
23
  end
24
24
 
25
- if (static_subscribers = Reactor::SUBSCRIBERS[name] || []).any?
25
+ static_subscribers = (Reactor::SUBSCRIBERS[name.to_s] || []) | (Reactor::SUBSCRIBERS['*'] || [])
26
+ if static_subscribers.any?
26
27
  static_subscribers.each do |callback|
27
28
  delay = callback[:options].try(:[], :delay) || 0
28
29
  case method = callback[:method]
29
30
  when Symbol
30
- callback[:source].delay_for(delay).send method, Reactor::Event.new(data.merge(event: name))
31
+ callback[:source].delay_for(delay).send method, Reactor::Event.new(data)
31
32
  else
32
- method.call Reactor::Event.new(data.merge(event: name))
33
+ method.call Reactor::Event.new(data)
33
34
  end
34
35
  end
35
36
  end
@@ -1,3 +1,3 @@
1
1
  module Reactor
2
- VERSION = "0.4.7"
2
+ VERSION = "0.5.0"
3
3
  end
data/spec/event_spec.rb CHANGED
@@ -38,7 +38,7 @@ describe Reactor::Event do
38
38
 
39
39
  it 'works with the legacy .process method, too' do
40
40
  Reactor::Subscriber.any_instance.should_receive(:fire).with(hash_including(actor_id: '1'))
41
- Reactor::Event.process(event_name, actor_id: '1')
41
+ Reactor::Event.perform(event_name, actor_id: '1')
42
42
  end
43
43
  end
44
44
 
@@ -9,6 +9,9 @@ class Auction < ActiveRecord::Base
9
9
  on_event :puppy_delivered, :ring_bell
10
10
  on_event :any_event, -> (event) { puppies! }
11
11
  on_event :pooped, :pick_up_poop, delay: 5.minutes
12
+ on_event '*' do |event|
13
+ event.actor.more_puppies! if event.name == 'another_event'
14
+ end
12
15
 
13
16
  def self.ring_bell(event)
14
17
  pp "ring ring! #{event}"
@@ -42,5 +45,10 @@ describe Reactor::Subscribable do
42
45
  Auction.should_receive(:puppies!)
43
46
  Reactor::Event.publish(:any_event)
44
47
  end
48
+
49
+ it 'accepts wildcard event name' do
50
+ Auction.any_instance.should_receive(:more_puppies!)
51
+ Reactor::Event.publish(:another_event, actor: Auction.create)
52
+ end
45
53
  end
46
- end
54
+ 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.4.7
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - winfred
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-08-07 00:00:00.000000000 Z
15
+ date: 2013-08-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: sidekiq