reactor 0.7.1 → 0.8.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: d90cd996f2190605f1a5371b4f53e6c4bc3e06c1
4
- data.tar.gz: 8f1fc2b3238366005a058b9682d69401075ef0ba
3
+ metadata.gz: 48d54ad63bce2589fbe3d6e39d8d9fe7e2d1fca6
4
+ data.tar.gz: 484fbf659d971b11479a0bd24392657ba4e9a031
5
5
  SHA512:
6
- metadata.gz: 29323bb0100ec4d4b912d44238c989aa9d5a94c94740cfa681917c62f42bf6c3d50f65ad4d7d170a863d3f3c1a3a55c656a9f0f74517bd4b47a3f297c0f1b27b
7
- data.tar.gz: fefd3d99e793f80d9a18f9989e303daf5ef193b83c04b4858874aec341ce8ea7560b08bdd64c9888f50b16c0dae96499a9c605ecf2c1a0ba5e5c99bd95043e77
6
+ metadata.gz: 32f14db9aba4a493b5a8765cf8b7d1a50723cc585215a40e0cb5bd8b8369d504871ec0288232e3dd647eb50ae5521b89577123af8708cf03bb8df61b413da995
7
+ data.tar.gz: 3c854cf77e8188db2598dba97e80cb40856fc3f70f497861508c99447147e1743840d7cc06c9c1997c87f6baa6a360d56257ae8a57b8074d96a65591f3e1b2a1
data/README.md CHANGED
@@ -220,16 +220,7 @@ for your testing convenience.
220
220
  4. Push to the branch (`git push origin my-new-feature`)
221
221
  5. Create new Pull Request
222
222
 
223
- ## Open Source by Hired
224
-
225
- [Hired](https://hired.com/?utm_source=opensource&utm_medium=reactor&utm_campaign=readme) wants to make sure every developer in the world has a kick-ass job with an awesome salary and great coworkers.
226
-
227
- Our site allows you to quickly create a profile and then get offers from some of the top companies in the world - with salary and equity disclosed up-front. Average Ruby engineer salaries on Hired are around $120,000 per year, but if you are smart enough to use Reactor you'll probably be able to get more like $150,000 :).
228
-
229
-
230
- <a href="https://hired.com/?utm_source=opensource&utm_medium=reactor&utm_campaign=readme-banner" target="_blank">
231
- <img src="https://dmrxx81gnj0ct.cloudfront.net/public/hired-banner-light-1-728x90.png" alt="Hired" width="728" height="90" align="center"/>
232
- </a>
223
+ ## Open Source by [Hired](https://hired.com/?utm_source=opensource&utm_medium=reactor&utm_campaign=readme)
233
224
 
234
225
  We are Ruby developers ourselves, and we use all of our open source projects in production. We always encourge forks, pull requests, and issues. Get in touch with the Hired Engineering team at _opensource@hired.com_.
235
226
 
data/lib/reactor/event.rb CHANGED
@@ -2,6 +2,8 @@ class Reactor::Event
2
2
  include Reactor::OptionallySubclassable
3
3
  include Sidekiq::Worker
4
4
 
5
+ class UnserializableModelKeysIncluded < StandardError; end;
6
+
5
7
  attr_accessor :data
6
8
 
7
9
  def initialize(data = {})
@@ -35,6 +37,8 @@ class Reactor::Event
35
37
  end
36
38
 
37
39
  def publish(name, data = {})
40
+ enforce_serializable_model_keys!(data)
41
+
38
42
  message = new(data.merge(event: name))
39
43
 
40
44
  if message.at.nil?
@@ -55,6 +59,22 @@ class Reactor::Event
55
59
  job.delete
56
60
  publish(name, data.except(:was)) if data[:at].future?
57
61
  end
62
+
63
+ private
64
+
65
+ def enforce_serializable_model_keys!(event_signature)
66
+ event_signature = event_signature.stringify_keys
67
+ serializable_models = event_signature.keys.map(&:to_s).select { |k| k.include?('_id') || k.include?('_type') }
68
+ .map { |k| k.gsub('_id', '') }
69
+ .map { |k| k.gsub('_type', '') }
70
+ .uniq
71
+
72
+ serializable_models.each do |model_relation_name|
73
+ raise UnserializableModelKeysIncluded, "#{model_relation_name}_type is missing corresponding _id key" if event_signature["#{model_relation_name}_id"].blank?
74
+ raise UnserializableModelKeysIncluded, "#{model_relation_name}_id is missing corresponding _type key" if event_signature["#{model_relation_name}_type"].blank?
75
+
76
+ end
77
+ end
58
78
  end
59
79
 
60
80
  private
@@ -1,3 +1,3 @@
1
1
  module Reactor
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
data/spec/event_spec.rb CHANGED
@@ -18,8 +18,20 @@ describe Reactor::Event do
18
18
 
19
19
  describe 'publish' do
20
20
  it 'fires the first perform and sets message event_id' do
21
- Reactor::Event.should_receive(:perform_async).with(event_name, 'actor_id' => '1', 'event' => :user_did_this)
22
- Reactor::Event.publish(:user_did_this, actor_id: '1')
21
+ Reactor::Event.should_receive(:perform_async).with(event_name, 'actor_id' => '1', 'actor_type' => 'Pet', 'event' => :user_did_this)
22
+ Reactor::Event.publish(:user_did_this, actor_id: '1', actor_type: 'Pet')
23
+ end
24
+
25
+ context 'x_id is included but x_type is not' do
26
+ it 'raises an exception' do
27
+ expect { Reactor::Event.publish(:user_did_something, actor_id: '1') }.to raise_error
28
+ end
29
+ end
30
+
31
+ context 'x_type is included but x_id is not' do
32
+ it 'raises an exception' do
33
+ expect { Reactor::Event.publish(:user_did_something, actor_type: 'Pet') }.to raise_error
34
+ end
23
35
  end
24
36
  end
25
37
 
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.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - winfred
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-06-26 00:00:00.000000000 Z
14
+ date: 2014-07-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: sidekiq