reactor 0.2.10 → 0.3.0
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 +4 -4
- data/README.md +34 -2
- data/lib/reactor/event.rb +6 -0
- data/lib/reactor/models/concerns/{eventable.rb → publishable.rb} +1 -1
- data/lib/reactor/models/concerns/subscribable.rb +9 -0
- data/lib/reactor/testing/matchers.rb +8 -0
- data/lib/reactor/version.rb +1 -1
- data/lib/reactor.rb +5 -3
- data/spec/models/concerns/{eventable_spec.rb → publishable_spec.rb} +1 -1
- data/spec/models/concerns/subscribable_spec.rb +18 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec3412b610bacc15fa57793c615761da1191b283
|
4
|
+
data.tar.gz: 0f8613b3601c6573dc6d6c15520e9ed0496f9d25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9d392a21a36ebf60fb6e07cb2505f1053dddd96a447a5d06b3b1595707e37ef716379e66d13dd56c2eaf926d5b612678d68fa159297d907eac6a7c166634568
|
7
|
+
data.tar.gz: 76a5d911946cbf24865daa12cddac19a627c1b4d3478b739e43f396bf64672f71b80881c9e643c6e9c8547ab6af7b005628d539de99e97508442540034652cd5
|
data/README.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Reactor
|
2
2
|
|
3
|
-
|
3
|
+
Warning: this is under active development!
|
4
|
+
|
5
|
+
This gem aims to provide the following tools to augment your ActiveRecord & Sidekiq stack.
|
6
|
+
|
7
|
+
1. Barebones event API through Sidekiq to publish whatever you want
|
8
|
+
2. Database-driven API to manage subscribers so that users may rewire whatever you let them (transactional emails, campaigns, etc...)
|
9
|
+
3. Static/Code-driven API to subscribe a basic ruby block to an event.
|
10
|
+
4. A new communication pattern between your ActiveRecord models that runs asynchronously through Sidekiq.
|
11
|
+
a. describe model lifecycle events and callbacks with class-level helper methods/DSL
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
@@ -18,7 +26,31 @@ Or install it yourself as:
|
|
18
26
|
|
19
27
|
## Usage
|
20
28
|
|
21
|
-
|
29
|
+
Well, this is evolving, so it's probably best to go read the specs.
|
30
|
+
|
31
|
+
|
32
|
+
### Barebones API
|
33
|
+
|
34
|
+
Event.publish(:event_name, any: 'data', you: 'want')
|
35
|
+
|
36
|
+
### ActiveModel extensions
|
37
|
+
|
38
|
+
#### Publishable
|
39
|
+
|
40
|
+
Describe lifecycle events like so
|
41
|
+
|
42
|
+
publishes :my_model_created
|
43
|
+
publishes :state_has_changed, if: -> { state_has_changed? }
|
44
|
+
|
45
|
+
#### Subscribable
|
46
|
+
|
47
|
+
*New in 0.3*
|
48
|
+
|
49
|
+
You can now bind any block to an event in your models like so
|
50
|
+
|
51
|
+
subscribes_to :any_event do |event|
|
52
|
+
MyModel.find(event.target).do_something_about_it!
|
53
|
+
end
|
22
54
|
|
23
55
|
## Contributing
|
24
56
|
|
data/lib/reactor/event.rb
CHANGED
@@ -55,6 +55,12 @@ class Reactor::Event
|
|
55
55
|
Reactor::Subscriber.where(event: '*').each do |s|
|
56
56
|
Reactor::Subscriber.delay.fire s.id, data
|
57
57
|
end
|
58
|
+
|
59
|
+
if (static_subscribers = Reactor::STATIC_SUBSCRIBERS[name.to_s] || []).any?
|
60
|
+
static_subscribers.each do |callback|
|
61
|
+
callback.call(Reactor::Event.new(data.merge(event: name.to_s)))
|
62
|
+
end
|
63
|
+
end
|
58
64
|
end
|
59
65
|
|
60
66
|
private
|
@@ -23,4 +23,12 @@ RSpec::Matchers.define :publish_events do |*events|
|
|
23
23
|
end
|
24
24
|
block.call
|
25
25
|
end
|
26
|
+
end
|
27
|
+
|
28
|
+
RSpec::Matchers.define :subscribe_to do |name, data = {}, &expectations|
|
29
|
+
|
30
|
+
match do
|
31
|
+
expectations.call if expectations.present?
|
32
|
+
Reactor::Event.publish(name, data)
|
33
|
+
end
|
26
34
|
end
|
data/lib/reactor/version.rb
CHANGED
data/lib/reactor.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require "reactor/version"
|
2
|
-
require "reactor/models/concerns/
|
2
|
+
require "reactor/models/concerns/publishable"
|
3
|
+
require "reactor/models/concerns/subscribable"
|
3
4
|
require "reactor/models/concerns/optionally_subclassable"
|
4
5
|
require "reactor/models/subscriber"
|
5
6
|
require "reactor/event"
|
6
7
|
|
7
8
|
module Reactor
|
8
|
-
|
9
|
+
STATIC_SUBSCRIBERS = {}
|
9
10
|
end
|
10
11
|
|
11
|
-
ActiveRecord::Base.send(:include, Reactor::
|
12
|
+
ActiveRecord::Base.send(:include, Reactor::Publishable)
|
13
|
+
ActiveRecord::Base.send(:include, Reactor::Subscribable)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class Auction < ActiveRecord::Base
|
5
|
+
subscribes_to :bid_made do |event|
|
6
|
+
event.target.update_column :status, 'first_bid_made'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Reactor::Subscribable do
|
11
|
+
|
12
|
+
describe 'subscribes_to' do
|
13
|
+
it 'binds block of code statically to event being fired' do
|
14
|
+
Auction.any_instance.should_receive(:update_column).with(:status, 'first_bid_made')
|
15
|
+
Reactor::Event.publish(:bid_made, target: Auction.create)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
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
|
+
version: 0.3.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-
|
12
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -70,14 +70,16 @@ files:
|
|
70
70
|
- Rakefile
|
71
71
|
- lib/reactor.rb
|
72
72
|
- lib/reactor/event.rb
|
73
|
-
- lib/reactor/models/concerns/eventable.rb
|
74
73
|
- lib/reactor/models/concerns/optionally_subclassable.rb
|
74
|
+
- lib/reactor/models/concerns/publishable.rb
|
75
|
+
- lib/reactor/models/concerns/subscribable.rb
|
75
76
|
- lib/reactor/models/subscriber.rb
|
76
77
|
- lib/reactor/testing/matchers.rb
|
77
78
|
- lib/reactor/version.rb
|
78
79
|
- reactor.gemspec
|
79
80
|
- spec/event_spec.rb
|
80
|
-
- spec/models/concerns/
|
81
|
+
- spec/models/concerns/publishable_spec.rb
|
82
|
+
- spec/models/concerns/subscribable_spec.rb
|
81
83
|
- spec/models/subscriber_spec.rb
|
82
84
|
- spec/spec_helper.rb
|
83
85
|
- spec/support/active_record.rb
|
@@ -107,7 +109,8 @@ specification_version: 4
|
|
107
109
|
summary: Sidekiq/ActiveRecord pubsub lib
|
108
110
|
test_files:
|
109
111
|
- spec/event_spec.rb
|
110
|
-
- spec/models/concerns/
|
112
|
+
- spec/models/concerns/publishable_spec.rb
|
113
|
+
- spec/models/concerns/subscribable_spec.rb
|
111
114
|
- spec/models/subscriber_spec.rb
|
112
115
|
- spec/spec_helper.rb
|
113
116
|
- spec/support/active_record.rb
|