resugan 0.1.1 → 0.1.2

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: 06266abd04e9aecee4b5a28654d177b0e2780dfd
4
- data.tar.gz: ff5a9e7c6a3bd73fe07c6572796aca4006812b11
3
+ metadata.gz: fd8a5dc134721f2feeff657ce31578f650431f66
4
+ data.tar.gz: 7767063fecb01571465c205054dfe5a51d7bc7c0
5
5
  SHA512:
6
- metadata.gz: e0465ac0358fb465cf1ccf2388d466c48a080eb0586362a313a3d9b4c701992fda770da3e3d835e74231ed9fb5c83b5914e7669c7b44c614444e5274e1aa2853
7
- data.tar.gz: 50d00661a3f35779bbda13d26fc86483fce997764fe987f0f0a2ea7ea72c3c8baf6e26815a182e8fd0bfdceb5196fcaf739bf47267d403bc298bfef86841277a
6
+ metadata.gz: 9f20caf6056410567a1b6ea5537c2d26d13cfa22339c4cc241c9854e7bc59272c998957ad206b13b49d6f37accfb414230dc39529653616abebd44fa8459657e
7
+ data.tar.gz: fa5ce6c2d39521b1a025b84d955905fb4b28d2feb2095714f9a6a38f216b237583d646667176ad0c3093542aea73afa7e562015f6638743c0a4b5f6cd74f6884
data/README.md CHANGED
@@ -24,13 +24,13 @@ Or install it yourself as:
24
24
  Register listeners:
25
25
 
26
26
  ```ruby
27
- Resugan::Kernel.register(:event2, ->(params) {
28
- puts "hello! event 2 has been called!"
29
- })
27
+ listener :event1 do |params|
28
+ puts "hello! event 2 has been called!"
29
+ end
30
30
 
31
- Resugan::Kernel.register(:hay, ->(params) {
32
- puts "hello! someone said hay!"
33
- })
31
+ listener :hay do |params|
32
+ puts "hello! someone said hay!"
33
+ end
34
34
  ```
35
35
 
36
36
  Generate events and wrap them in a resugan block:
@@ -10,13 +10,16 @@ module Resugan
10
10
  @dispatchers[namespace] = dispatcher
11
11
  end
12
12
 
13
- def self.register(event, block)
13
+ def self.register(event, &block)
14
14
  register_with_namespace("", event, block)
15
15
  end
16
16
 
17
- def self.register_with_namespace(namespace, event, block)
17
+ def self.register_with_namespace(namespace, event, listener_id = nil, block)
18
+ @listener_ids = {} unless @listener_ids
18
19
  @listener = {} unless @listener
19
20
 
21
+ return self if listener_id && @listener_ids["#{namespace}_#{listener_id}"]
22
+
20
23
  event = "#{namespace}_#{event}".to_sym
21
24
 
22
25
  unless @listener[event]
@@ -25,6 +28,8 @@ module Resugan
25
28
  @listener[event] << block
26
29
  end
27
30
 
31
+ @listener_ids["#{namespace}_#{listener_id}"] = block if listener_id
32
+
28
33
  self
29
34
  end
30
35
 
@@ -42,6 +47,7 @@ module Resugan
42
47
  end
43
48
 
44
49
  def self.clear
50
+ @listener_ids.clear if @listener_ids
45
51
  @listener.clear if @listener
46
52
  end
47
53
  end
@@ -15,4 +15,10 @@ class Object
15
15
  current_thread.resugan_context.register(event, params)
16
16
  end
17
17
  end
18
+
19
+ def listener(event, options = {}, &block)
20
+ Resugan::Kernel.register_with_namespace(options[:namespace], event, options[:id], ->(params) {
21
+ block.call(params)
22
+ })
23
+ end
18
24
  end
@@ -1,3 +1,3 @@
1
1
  module Resugan
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Emmanuel Dayo