resugan 0.1.12 → 0.1.13

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: 9654ca7f5f98456f020eb91f5bc89498957b6fe9
4
- data.tar.gz: 5ee0ae2b994d3bec9077d0025f3683c1aba9c3f0
3
+ metadata.gz: ba18c2c784e29ca7493bbb579f33a75c31b41ae6
4
+ data.tar.gz: e47f70a4106daa799f18e3df9a157b2ba42ab50a
5
5
  SHA512:
6
- metadata.gz: 52f12f972eb824baa776710c7fd0b98f805ab790cc491be0403db7881a9ca90affd80623f7266ae27da09a0b20d95421c2614615295813beaf698770374b17f3
7
- data.tar.gz: 7e57c11239e0aecfb94162094f2260c5f998cf997e21f2f600e8eb8af0310cfca7fdb2807370a94aefd5f5e444d202e34c507dd9ea51f1562d0b9f20bc8eaf57
6
+ metadata.gz: c9a89df390d48392b0526686d6aaf863f87c6e53385ef6d8449ccd2acfa7a1a38b7da5e7045a2032eab8c13ee8e5685a8a2085286556bb5bb7e354cb087c308c
7
+ data.tar.gz: 1d8be70ec1599f09e87b1380eaaf98ef195f8948c08c19ba5a994114a05e94487bf86f15f45ccce6f74ae98e72d348dec9039f6f40029e67e20a40c735f64350
data/README.md CHANGED
@@ -155,11 +155,22 @@ if you want to make sure that listener only gets executed once you can pass an i
155
155
  option:
156
156
 
157
157
  ```ruby
158
- listener :event1, id: 'no_other_listener_like_this' do |array|
158
+ _listener :event1, id: 'no_other_listener_like_this' do |array|
159
159
  # some code that gets executed
160
160
  end
161
161
  ```
162
162
 
163
+ Or you can use the _listener! form which make sure a certain block is limited to
164
+ only a single instance.
165
+
166
+ ```ruby
167
+ 2.times do |i|
168
+ _listener! :event1 do |array|
169
+ # There will be only one instance of this listener no matter how many times it is defined
170
+ end
171
+ end
172
+ ```
173
+
163
174
  ## Customizing the Event dispatcher
164
175
 
165
176
  The way events are consumed is entirely customizable. You can register your own event dispatcher:
@@ -191,7 +202,7 @@ Or assign it to a specific namespace:
191
202
 
192
203
  This allows you to use various queue backends per namespace, like resugan-worker for example.
193
204
 
194
- ## Debugging
205
+ ### Debugging
195
206
 
196
207
  Sometimes you need to track where events are fired. You can do so by enabling line tracing:
197
208
 
@@ -212,9 +223,9 @@ puts(resugan {
212
223
  {:event1=>[{:params=>{:_source=>"/Users/jedld/workspace/resugan/spec/resugan_spec.rb:144:in `block (5 levels) in <top (required)>'"}}]}
213
224
  ```
214
225
 
215
- ## Using Resugan::Engine::MarshalledInlineDispatcher
226
+ ### Using Resugan::Engine::MarshalledInlineDispatcher
216
227
 
217
- By default, resugan uses the Resugan::Engine::InlineDispatcher as the default dispatcher for
228
+ By default, resugan uses the Resugan::Engine::InlineDispatcher as the default dispatcher for
218
229
  all namespaces. For performance reasons, params passed to the _fire method are passed as is, but there are
219
230
  times when you want to simulate params that are passed using JSON.parse as is the case
220
231
  when using a custom dispatcher that uses redis (see resugan-worker). In this case you may set MarshalledInlineDispatcher
@@ -224,12 +235,12 @@ as the default dispatcher for test and development environment instead (e.g. rai
224
235
  Resugan::Kernel.set_default_dispatcher(Resugan::Engine::MarshalledInlineDispatcher) if Rails.env.development? || Rails.env.test?
225
236
  ```
226
237
 
227
- ## Related Projects
238
+ Related Projects
239
+ =================
228
240
 
229
241
  Below are projects that extend resugan.
230
242
 
231
- Resugan Worker
232
- --------------
243
+ ### Resugan Worker
233
244
 
234
245
  A project that wraps resugan listeners to be consumed using an external worker. Think of this as a redis queue backend.
235
246
  Can also be used as a sample on how to extend resugan.
@@ -238,7 +249,9 @@ https://github.com/jedld/resugan-worker
238
249
 
239
250
  ## Similar Projects
240
251
 
241
- wisper (https://github.com/krisleech/wisper) - An excellent gem that focuses on a pub-sub model. Though its global listeners somehow have the same effect though in a syntactically different way than resugan.
252
+ wisper (https://github.com/krisleech/wisper) - An excellent gem that focuses on a coupled pub-sub model. Though its global listeners somehow have the same effect though in a syntactically different way.
253
+
254
+ event_bus (https://github.com/kevinrutherford/event_bus) - Loosely coupled pub-sub similar to resugan
242
255
 
243
256
  ## Development
244
257
 
@@ -27,4 +27,10 @@ class Object
27
27
  block.call(params)
28
28
  })
29
29
  end
30
+
31
+ def _listener!(event, options = {}, &block)
32
+ Resugan::Kernel.register_with_namespace(options[:namespace], event, options[:id] || caller[0], ->(params) {
33
+ block.call(params)
34
+ })
35
+ end
30
36
  end
@@ -1,3 +1,3 @@
1
1
  module Resugan
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resugan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Emmanuel Dayo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-29 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler