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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88d609ceb9bb193c8f9e9ee4d5a8dbb630df4af3
4
- data.tar.gz: 0b17ef65ca99017bfb607768038a12a06630de9f
3
+ metadata.gz: 8436d6c33951f98da4d83996218eabaca1425f07
4
+ data.tar.gz: 3bdc108d04b3ae9a7140212ead07f9e0d3aceef4
5
5
  SHA512:
6
- metadata.gz: 63df0e7c2880d62ff5a63341edb415b27af0f9cba0498b2b027d8cc851aab808e91d5073c5da6706c5e150ea4d05cb6c779577867fc3038f5fe5cabbe7517536
7
- data.tar.gz: 1a3117e59f97bf13f769c4516be6cb4c3a85a7c79b434a38e681e69825e3c2a93b0fa3614d00655e5c9a4193377b5d16f1bf47c12f570e5280af1c7b670f03f7
6
+ metadata.gz: bb6cea9e23d0d5012c8bca0deaced58cbe04c55fa3845ba6beb6872326d9590a335adc2491300dd1e5a89b060e9d29eec43ee426158a10c457fc57c8568cafc4
7
+ data.tar.gz: 171ec8152a6b3a49598eed4c351836f720adea8c9ba323a6eeefd2a53f3edd4217491fc6bc3fa167f332a30a1ba0cdd8f81f959e63334c277c7f6ef73a793667
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ = Version 0.1.11
2
+ * Allow listeners to attach to multiple namespaces to allow for DRY'er code
3
+
1
4
  = Version 0.1.8
2
5
  * First real version for public consumption
3
6
 
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
@@ -40,27 +40,32 @@ module Resugan
40
40
  register_with_namespace("", event, block)
41
41
  end
42
42
 
43
- def self.register_with_namespace(namespace, event, listener_id = nil, block)
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
- return self if listener_id && @listener_ids["#{namespace}_#{listener_id}"]
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
- event = "#{namespace}_#{event}".to_sym
51
+ event = "#{n}_#{event_type}".to_sym
50
52
 
51
- unless @_listener[event]
52
- @_listener[event] = [block]
53
- else
54
- @_listener[event] << block
55
- end
53
+ unless @_listener[event]
54
+ @_listener[event] = [block]
55
+ else
56
+ @_listener[event] << block
57
+ end
56
58
 
57
- @listener_ids["#{namespace}_#{listener_id}"] = block if listener_id
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'] })
@@ -1,3 +1,3 @@
1
1
  module Resugan
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resugan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Emmanuel Dayo