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 +4 -4
- data/README.md +6 -6
- data/lib/resugan/kernel.rb +8 -2
- data/lib/resugan/object.rb +6 -0
- 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: fd8a5dc134721f2feeff657ce31578f650431f66
|
4
|
+
data.tar.gz: 7767063fecb01571465c205054dfe5a51d7bc7c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
28
|
-
|
29
|
-
|
27
|
+
listener :event1 do |params|
|
28
|
+
puts "hello! event 2 has been called!"
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
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:
|
data/lib/resugan/kernel.rb
CHANGED
@@ -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
|
data/lib/resugan/object.rb
CHANGED
@@ -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
|
data/lib/resugan/version.rb
CHANGED