em_remote_call 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/em_remote_call/server.rb +11 -2
- data/lib/em_remote_call/version.rb +1 -1
- data/spec/integration_spec.rb +46 -0
- metadata +3 -3
@@ -33,8 +33,17 @@ module EM::RemoteCall::Server
|
|
33
33
|
def json_parsed(hash)
|
34
34
|
remote_call = EM::RemoteCall::Call.new hash[:instance], hash[:method].to_sym, hash[:argument]
|
35
35
|
|
36
|
-
remote_call.call do |
|
37
|
-
send_data({:deferrable_id => hash[:deferrable_id], :success =>
|
36
|
+
ret = remote_call.call do |result|
|
37
|
+
send_data({:deferrable_id => hash[:deferrable_id], :success => result})
|
38
|
+
end
|
39
|
+
|
40
|
+
if ret.is_a? EM::Deferrable
|
41
|
+
ret.callback do |result|
|
42
|
+
send_data({:deferrable_id => hash[:deferrable_id], :success => result})
|
43
|
+
end
|
44
|
+
ret.errback do |result|
|
45
|
+
send_data({:deferrable_id => hash[:deferrable_id], :error => result})
|
46
|
+
end
|
38
47
|
end
|
39
48
|
|
40
49
|
rescue => e
|
data/spec/integration_spec.rb
CHANGED
@@ -30,6 +30,12 @@ class ServerTrack < Track
|
|
30
30
|
def raise_hell
|
31
31
|
raise 'foobar'
|
32
32
|
end
|
33
|
+
def with_deferrable(outcome = 'succeed') # does not take a block
|
34
|
+
d = EventMachine::DefaultDeferrable.new
|
35
|
+
d.send outcome
|
36
|
+
return d
|
37
|
+
end
|
38
|
+
|
33
39
|
def self.some_class_meth
|
34
40
|
yield
|
35
41
|
end
|
@@ -40,6 +46,7 @@ class ClientTrack < Track
|
|
40
46
|
remote_method :init_track_on_server, :class_name => 'ServerTrack', :calls => :new
|
41
47
|
remote_method :play, :class_name => 'ServerTrack', :find_by => :id
|
42
48
|
remote_method :raise_hell, :class_name => 'ServerTrack', :find_by => :id
|
49
|
+
remote_method :with_deferrable, :class_name => 'ServerTrack', :find_by => :id
|
43
50
|
|
44
51
|
class << self
|
45
52
|
extend EM::RemoteCall
|
@@ -111,4 +118,43 @@ describe EM::RemoteCall do
|
|
111
118
|
end
|
112
119
|
end
|
113
120
|
end
|
121
|
+
describe "with a deferrable" do
|
122
|
+
describe "on success" do
|
123
|
+
describe "with a block" do
|
124
|
+
it "should use the block as callback" do
|
125
|
+
test_on_client do
|
126
|
+
callb = mock(:callb)
|
127
|
+
callb.should_receive(:foo).with()
|
128
|
+
c = ClientTrack.new
|
129
|
+
c.init_track_on_server({})
|
130
|
+
c.with_deferrable(:succeed){ callb.foo }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
describe "with callback" do
|
135
|
+
it "should use callback" do
|
136
|
+
test_on_client do
|
137
|
+
callb = mock(:callb)
|
138
|
+
callb.should_receive(:foo).with()
|
139
|
+
c = ClientTrack.new
|
140
|
+
c.init_track_on_server({})
|
141
|
+
play_call = c.with_deferrable(:succeed)
|
142
|
+
play_call.callback{ callb.foo }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
describe "on error" do
|
148
|
+
it "should use errback" do
|
149
|
+
test_on_client do
|
150
|
+
callb = mock(:callb)
|
151
|
+
callb.should_receive(:foo).with()
|
152
|
+
c = ClientTrack.new
|
153
|
+
c.init_track_on_server({})
|
154
|
+
play_call = c.with_deferrable(:fail)
|
155
|
+
play_call.errback{ callb.foo }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
114
160
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Niko Dittmann
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-23 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|