motion-wiretap 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/motion-wiretap/all/signal.rb +27 -8
- data/lib/motion-wiretap/all/wiretap.rb +12 -2
- data/lib/motion-wiretap/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: 99db3db8e4cf9422189294a89b8291de93af7548
|
4
|
+
data.tar.gz: f8565d3e0cde697b9ca8c02bdf1f932f0ce635bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e217902b0a8c869efcf462ad728046dffcd492a613781e8284d2db7449caa4e2780bdeebc0390eda3a453fdc7a6c4282c89314d767f61e0e757ddde2955ec6a
|
7
|
+
data.tar.gz: 64755e1482c0fb48241805ff5d30a41832833a3fb77d9878ef25e01fbf2612575844eff88aa8a71621f8321ec61fd1856f392ce6c435c8599bfecf6e76b95f8a
|
@@ -4,10 +4,9 @@ module MotionWiretap
|
|
4
4
|
# Signal is triggered with a new value, or it is completed, or canceled with
|
5
5
|
# an error event.
|
6
6
|
class Signal < Wiretap
|
7
|
-
# This is the default initial value - it does not trigger a 'change' event.
|
8
|
-
# This value is for internal use only.
|
9
|
-
SINGLETON = Class.new.new
|
10
7
|
|
8
|
+
# The SINGLETON value does not trigger a 'change' event. It is for internal
|
9
|
+
# use only.
|
11
10
|
def initialize(value=SINGLETON, &block)
|
12
11
|
@value = value
|
13
12
|
super(&block)
|
@@ -21,17 +20,37 @@ module MotionWiretap
|
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# If you pass multiple values to this method, the 'value' will be the array
|
24
|
+
# of all the values, but they will be passed on to 'trigger_changed' using
|
25
|
+
# the splat operator, and so will be passed to listener blocks as individual
|
26
|
+
# arguments.
|
27
|
+
#
|
28
|
+
# Example:
|
29
|
+
# signal = Signal.new
|
30
|
+
# signal.listen do |a, b|
|
31
|
+
# @added = a + b
|
32
|
+
# end
|
33
|
+
# signal.next(1, 5) # works great, @added will be 6
|
34
|
+
# signal.next([1, 5]) # this works, too, because of how args are assigned to blocks in ruby
|
35
|
+
# signal.next(1) # a will be 1 and b will be nil (error!)
|
36
|
+
def next(value, *values)
|
37
|
+
if values.length > 0
|
38
|
+
raise "don't do that please" if values.include? SINGLETON
|
39
|
+
value = [value].concat values
|
40
|
+
@value = value
|
41
|
+
trigger_changed(*value)
|
42
|
+
else
|
43
|
+
raise "don't do that please" if value == SINGLETON
|
44
|
+
@value = value
|
45
|
+
trigger_changed(@value)
|
46
|
+
end
|
28
47
|
end
|
29
48
|
|
30
49
|
def complete
|
31
50
|
trigger_completed
|
32
51
|
end
|
33
52
|
|
34
|
-
def error(error)
|
53
|
+
def error(error=SINGLETON)
|
35
54
|
trigger_error(error)
|
36
55
|
end
|
37
56
|
|
@@ -4,6 +4,10 @@ end
|
|
4
4
|
|
5
5
|
module MotionWiretap
|
6
6
|
|
7
|
+
# This placeholder value is used anywhere you want to accept any value,
|
8
|
+
# including nil.
|
9
|
+
SINGLETON = Class.new.new
|
10
|
+
|
7
11
|
class Wiretap
|
8
12
|
|
9
13
|
def initialize(&block)
|
@@ -74,6 +78,7 @@ module MotionWiretap
|
|
74
78
|
return self
|
75
79
|
end
|
76
80
|
|
81
|
+
# Sends the block or wiretap a changed signal
|
77
82
|
def trigger_changed_on(block_or_wiretap, values)
|
78
83
|
if block_or_wiretap.is_a? Wiretap
|
79
84
|
block_or_wiretap.trigger_changed(*values)
|
@@ -107,6 +112,7 @@ module MotionWiretap
|
|
107
112
|
return self
|
108
113
|
end
|
109
114
|
|
115
|
+
# Sends the block or wiretap a completed signal
|
110
116
|
def trigger_completed_on(block_or_wiretap)
|
111
117
|
if block_or_wiretap.is_a? Wiretap
|
112
118
|
block_or_wiretap.trigger_completed
|
@@ -128,9 +134,12 @@ module MotionWiretap
|
|
128
134
|
return self
|
129
135
|
end
|
130
136
|
|
131
|
-
def trigger_error(error)
|
137
|
+
def trigger_error(error=SINGLETON)
|
132
138
|
return if @is_torn_down || @is_completed || @is_error
|
133
|
-
|
139
|
+
raise "You must pass a truthy value to `trigger_error()`" unless error
|
140
|
+
|
141
|
+
# convert SINGLETON to a default error value
|
142
|
+
error = true if error == SINGLETON
|
134
143
|
@is_error = error
|
135
144
|
|
136
145
|
@error_handlers.each do |block_or_wiretap|
|
@@ -141,6 +150,7 @@ module MotionWiretap
|
|
141
150
|
return self
|
142
151
|
end
|
143
152
|
|
153
|
+
# Sends the block or wiretap an error value
|
144
154
|
def trigger_error_on(block_or_wiretap, error)
|
145
155
|
if block_or_wiretap.is_a? Wiretap
|
146
156
|
block_or_wiretap.trigger_error(error)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-wiretap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin T.A. Gray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
ReactiveCocoa is an amazing system, and RubyMotion could benefit from the
|