redispatcher 0.0.1 → 0.0.2
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 +27 -0
- data/lib/redispatcher.rb +1 -1
- data/lib/redispatcher/callbacks.rb +14 -12
- data/lib/redispatcher/dispatchable.rb +1 -1
- data/lib/redispatcher/dispatcher.rb +8 -7
- data/redispatcher.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a1dba3c146a45fc5d21299e409df5d8b860aa9b
|
4
|
+
data.tar.gz: ad10a86219e6f1fc18b7513f24d20f3256e088f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b99d6b2df35ce4196a748ef9a39d65c901377008d31d6b7479004b1968c5d2fa8cc29d4bc3905a4a209e01865a660112431cdfda4e86da00ebed801b341d180
|
7
|
+
data.tar.gz: 29e17215b38690bc68d37171d61f18dc2f07fa9b27bcc577de76ab81e76f998d72b922db821c3dd3674edbdb649cfdc8e481bdc4bf562d698586241244390cb0
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|

|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/redispatcher)
|
4
|
+
[](https://codeclimate.com/github/rambler-digital-solutions/redispatcher)
|
5
|
+
[](https://codeclimate.com/github/rambler-digital-solutions/redispatcher)
|
6
|
+
|
3
7
|
Dispatch ActiveRecord objects to any structures with ease.
|
4
8
|
|
5
9
|
## Installation
|
@@ -30,6 +34,29 @@ class TopicDispatcher < Redispatcher::Dispatcher
|
|
30
34
|
end
|
31
35
|
```
|
32
36
|
|
37
|
+
|
38
|
+
Do not hesitate to use dispatscher's callbacks `before_` and `after_` `initialize`, `process`, `commit`, `rollback` just like that:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# app/dispatchers/topic_dispatcher.rb
|
42
|
+
class TopicDispatcher < Redispatcher::Dispatcher
|
43
|
+
|
44
|
+
after_initialize do
|
45
|
+
@processed_object = {}
|
46
|
+
end
|
47
|
+
|
48
|
+
before_process do
|
49
|
+
@processed_object.merge! title: object.title
|
50
|
+
end
|
51
|
+
|
52
|
+
after_commit :update_mongodb
|
53
|
+
|
54
|
+
def update_mongodb
|
55
|
+
MONGO['topics'].update({ id: object.id }, processed_object, upsert: true)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
33
60
|
### Enable dispatcher for your model
|
34
61
|
|
35
62
|
```ruby
|
data/lib/redispatcher.rb
CHANGED
@@ -6,24 +6,26 @@ module Redispatcher
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ClassMethods
|
9
|
-
def define_dispatcher_callbacks
|
10
|
-
define_callbacks
|
9
|
+
def define_dispatcher_callbacks(*callbacks)
|
10
|
+
define_callbacks(*callbacks.flatten)
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
callbacks.each do |callback|
|
13
|
+
eval <<-end_callbacks
|
14
|
+
def before_#{callback}(*args, &block)
|
15
|
+
set_callback(:#{callback}, :before, *args, &block)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def after_#{callback}(*args, &block)
|
19
|
+
set_callback(:#{callback}, :after, *args, &block)
|
20
|
+
end
|
21
|
+
end_callbacks
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
module InstanceMethods
|
25
|
-
def run_dispatcher_callbacks(&block)
|
26
|
-
run_callbacks(
|
27
|
+
def run_dispatcher_callbacks(callback, &block)
|
28
|
+
run_callbacks(callback, &block)
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -1,15 +1,16 @@
|
|
1
1
|
module Redispatcher
|
2
2
|
class Dispatcher
|
3
3
|
include ActiveSupport::Callbacks
|
4
|
+
include Callbacks
|
4
5
|
include Logger
|
5
6
|
|
6
|
-
|
7
|
+
define_dispatcher_callbacks(:initialize, :process, :commit, :rollback)
|
7
8
|
|
8
|
-
|
9
|
+
after_commit do
|
9
10
|
log "successfully dispatched"
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
after_rollback do
|
13
14
|
log "dispatching failed"
|
14
15
|
end
|
15
16
|
|
@@ -18,26 +19,26 @@ module Redispatcher
|
|
18
19
|
def initialize(object, options={})
|
19
20
|
@object = object
|
20
21
|
@options = options
|
21
|
-
|
22
|
+
run_dispatcher_callbacks :initialize do
|
22
23
|
log "initialize callback"
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def process
|
27
|
-
|
28
|
+
run_dispatcher_callbacks :process do
|
28
29
|
log "process callback"
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
33
|
def commit
|
33
|
-
|
34
|
+
run_dispatcher_callbacks :commit do
|
34
35
|
log "commit callback"
|
35
36
|
end
|
36
37
|
processed_object
|
37
38
|
end
|
38
39
|
|
39
40
|
def rollback
|
40
|
-
|
41
|
+
run_dispatcher_callbacks :rollback do
|
41
42
|
log "rollback callback"
|
42
43
|
end
|
43
44
|
end
|
data/redispatcher.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'redispatcher'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.2'
|
8
8
|
spec.authors = ['Sergey Besedin']
|
9
9
|
spec.email = ['kr3ssh@gmail.com']
|
10
10
|
spec.summary = %q{Gem to dispatch ActiveRecord objects to anywhere}
|