resugan 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/README.md +23 -1
- data/lib/resugan/kernel.rb +14 -9
- data/lib/resugan/version.rb +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: 8436d6c33951f98da4d83996218eabaca1425f07
|
4
|
+
data.tar.gz: 3bdc108d04b3ae9a7140212ead07f9e0d3aceef4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb6cea9e23d0d5012c8bca0deaced58cbe04c55fa3845ba6beb6872326d9590a335adc2491300dd1e5a89b060e9d29eec43ee426158a10c457fc57c8568cafc4
|
7
|
+
data.tar.gz: 171ec8152a6b3a49598eed4c351836f720adea8c9ba323a6eeefd2a53f3edd4217491fc6bc3fa167f332a30a1ba0cdd8f81f959e63334c277c7f6ef73a793667
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
Simple, powerful and unobstrusive event driven architecture framework for ruby. This gem provides
|
6
6
|
a base framework in order to build a more powerful event based system on top of it. Events cuts across multiple objects and allows you to cleanly separate business logic to other cross cutting concerns like analytics and logging. Multiple events are consolidated allowing you to efficiently batch related operations together.
|
7
7
|
|
8
|
+
Also allows for a customizable backend which enables the use of various evented queuing mechanisms
|
9
|
+
like redis queue, amazon sqs with minimal changes to your code that generates the events.
|
10
|
+
|
8
11
|
## Installation
|
9
12
|
|
10
13
|
Add this line to your application's Gemfile:
|
@@ -108,17 +111,34 @@ Resugan supports namespaces, allowing you to group listeners and trigger them se
|
|
108
111
|
puts "hello! someone said hay!"
|
109
112
|
end
|
110
113
|
|
114
|
+
_listener :log, namespace: %w(group1 group2) do |params|
|
115
|
+
params.each {
|
116
|
+
puts "listener that belongs to 2 namespaces"
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
111
120
|
resugan "group1" do
|
112
121
|
_fire :event1
|
122
|
+
_fire :log
|
113
123
|
end
|
114
124
|
|
115
125
|
resugan "group2" do
|
116
126
|
_fire :event1
|
127
|
+
_fire :log
|
117
128
|
end
|
118
129
|
```
|
119
130
|
|
120
131
|
Behavior is as expected. Events under group1 will only be handled by listeners under group1 and so on.
|
121
132
|
|
133
|
+
The above should print:
|
134
|
+
|
135
|
+
```
|
136
|
+
hello! event 2 has been called!
|
137
|
+
listener that belongs to 2 namespaces
|
138
|
+
hello! someone said hay!
|
139
|
+
listener that belongs to 2 namespaces
|
140
|
+
```
|
141
|
+
|
122
142
|
## Customizing the Event dispatcher
|
123
143
|
|
124
144
|
The way events are consumed is entirely customizable. You can register your own event dispatcher:
|
@@ -148,6 +168,8 @@ Or assign it to a specific namespace:
|
|
148
168
|
Resugan::Kernel.register_dispatcher(MyCustomerDispatcher, 'CustomGroup')
|
149
169
|
```
|
150
170
|
|
171
|
+
This allows you to use various queue backends per namespace, like resugan-worker for example.
|
172
|
+
|
151
173
|
## Debugging
|
152
174
|
|
153
175
|
Sometimes you need to track where events are fired. You can do so by enabling line tracing:
|
@@ -176,7 +198,7 @@ Below are projects that extend resugan.
|
|
176
198
|
Resugan Worker
|
177
199
|
--------------
|
178
200
|
|
179
|
-
A project that wraps resugan listeners to be consumed using an external worker.
|
201
|
+
A project that wraps resugan listeners to be consumed using an external worker. Think of this as a redis queue backend.
|
180
202
|
Can also be used as a sample on how to extend resugan.
|
181
203
|
|
182
204
|
https://github.com/jedld/resugan-worker
|
data/lib/resugan/kernel.rb
CHANGED
@@ -40,27 +40,32 @@ module Resugan
|
|
40
40
|
register_with_namespace("", event, block)
|
41
41
|
end
|
42
42
|
|
43
|
-
def self.register_with_namespace(
|
43
|
+
def self.register_with_namespace(namespaces, event_type, listener_id = nil, block)
|
44
44
|
@listener_ids = {} unless @listener_ids
|
45
45
|
@_listener = {} unless @_listener
|
46
46
|
|
47
|
-
|
47
|
+
namespaces = namespaces.is_a?(Array) ? namespaces : [namespaces]
|
48
|
+
namespaces.each do |n|
|
49
|
+
next if listener_id && @listener_ids["#{n}_#{listener_id}"]
|
48
50
|
|
49
|
-
|
51
|
+
event = "#{n}_#{event_type}".to_sym
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
unless @_listener[event]
|
54
|
+
@_listener[event] = [block]
|
55
|
+
else
|
56
|
+
@_listener[event] << block
|
57
|
+
end
|
56
58
|
|
57
|
-
|
59
|
+
@listener_ids["#{n}_#{listener_id}"] = block if listener_id
|
60
|
+
end
|
58
61
|
|
59
62
|
self
|
60
63
|
end
|
61
64
|
|
62
65
|
def self.invoke(namespace, event, payload = [])
|
63
66
|
event = "#{namespace}_#{event}".to_sym
|
67
|
+
puts "invoke"
|
68
|
+
p @_listener
|
64
69
|
if @_listener && @_listener[event]
|
65
70
|
@_listener[event].each do |_listener|
|
66
71
|
_listener.call(payload.map { |p| p[:params] || p['params'] })
|
data/lib/resugan/version.rb
CHANGED