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 +4 -4
- data/README.md +1 -10
- data/lib/reactor/event.rb +20 -0
- data/lib/reactor/version.rb +1 -1
- data/spec/event_spec.rb +14 -2
- 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: 48d54ad63bce2589fbe3d6e39d8d9fe7e2d1fca6
|
4
|
+
data.tar.gz: 484fbf659d971b11479a0bd24392657ba4e9a031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/reactor/version.rb
CHANGED
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.
|
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-
|
14
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: sidekiq
|