tardvig 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tardvig/events/proxy.rb +24 -8
- data/lib/tardvig/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c2202e722e19d6b70cd47740cb0b59a16d4f7de
|
4
|
+
data.tar.gz: 083573b0dd0803e3017476b886669e698f06df30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3bd839717b9c981c01d6108e6d7ebda3c97da3d24bdfe11985342c813e1fda778b7654b5ec1d70a43ccb2c62555d6e191e8e022888fb1a8f2f1513ff2e3c941
|
7
|
+
data.tar.gz: 8d8e63e94588de9bcdd27a03d7edd9582ddcfa32a9bd74a971616f5f4cb1507bf8a5e25e50e41bcfa9c8eb68df8caa94cb1c5725e85fbc9da88a58dff7bc96ee
|
data/lib/tardvig/events/proxy.rb
CHANGED
@@ -4,19 +4,32 @@ module Tardvig
|
|
4
4
|
# It is useful when you do not have a direct access to object which you
|
5
5
|
# are want to listen on, for example, when you have access only to GameIO
|
6
6
|
# from a display.
|
7
|
+
#
|
8
|
+
# To proxy an event from an object, you need to add this object to
|
9
|
+
# {#tracked_list} through {#spy_on} and then you can bind a listener on it
|
10
|
+
# through proxy (see {#on} for syntax).
|
11
|
+
#
|
12
|
+
# If you want proxy to forward event to itself even if you have not bound a
|
13
|
+
# listener, you can trigger the `:wait_for_event` event on the proxy.
|
14
|
+
# You should pass the name of the event you are waiting for as an argument.
|
7
15
|
module Proxy
|
8
16
|
# Adds objects to tracked list so you can bind proxy listeners to them
|
9
17
|
# @param [Hash] `name: object` pairs.
|
10
18
|
def spy_on(objects)
|
11
19
|
tracked_list.merge! objects
|
12
20
|
end
|
13
|
-
|
21
|
+
|
14
22
|
# @return [Hash] objects (with their names as keys) which you can bind
|
15
23
|
# proxy listeners to.
|
16
24
|
def tracked_list
|
17
25
|
@tracked_list ||= ({}.extend DataIdentifier)
|
18
26
|
end
|
19
|
-
|
27
|
+
|
28
|
+
def happen(event, data = nil)
|
29
|
+
track_event data if event == :wait_for_event
|
30
|
+
super event, data
|
31
|
+
end
|
32
|
+
|
20
33
|
# It works like the original Events#on, but it also can bind listeners
|
21
34
|
# to objects from the {tracked_list}.
|
22
35
|
#
|
@@ -31,8 +44,15 @@ module Tardvig
|
|
31
44
|
# to this event. *Important!* When you will trigger this event, its name
|
32
45
|
# must be a Symbol.
|
33
46
|
#
|
34
|
-
# See spec if you
|
47
|
+
# See spec if you have not understood.
|
35
48
|
def on(event, &listener)
|
49
|
+
track_event event
|
50
|
+
super event, &listener
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def track_event(event)
|
36
56
|
event_id_parts = event.to_s.split ':'
|
37
57
|
if event_id_parts.size == 2
|
38
58
|
event_target = tracked_list.get_this event_id_parts[0]
|
@@ -40,12 +60,8 @@ module Tardvig
|
|
40
60
|
bind_proxy_listener event_target, event, event_id_parts[1]
|
41
61
|
end
|
42
62
|
end
|
43
|
-
super event, &listener
|
44
63
|
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
|
64
|
+
|
49
65
|
def bind_proxy_listener(target, full_event_name, event_name)
|
50
66
|
target.on event_name.to_sym do |data|
|
51
67
|
happen full_event_name, data
|
data/lib/tardvig/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tardvig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vadim Saprykin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|