farcall 0.3.0 → 0.3.1

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: 7ccf7c600e32b64b16b3ee5e278064bef7214274
4
- data.tar.gz: 2e7fc842321b53483a09b02caf9cc9c8fc8af85f
3
+ metadata.gz: 963744c3ea9c75aceaed2bd2add46e9d6a39e88d
4
+ data.tar.gz: 1debec27b99b58d68314425b47999c12499e1e39
5
5
  SHA512:
6
- metadata.gz: 611fea3359ae86917d1625f8b1daf79e78c4cf20421a8ee64d3e679a00fbe0007a8bd79a551fb9e24bf6d38e3eea47dc9e77ac92927cb05c7c66f51d0ae8749e
7
- data.tar.gz: 4010ab7cf9dbe52c2e4ca519c3df823a5ea104ff7783118340e576ebd2551c0866b20967c55b82e0a8a23e00a7314a73362efb433db6da9f092a8386c1388afe
6
+ metadata.gz: 2ddc0f4b278c77c6671ab8f612355729de473b309389dc208ff1d51753907d0abac92aa3f7bda719cff39975134018123d032c7700c231e4be464d0e4218e0a0
7
+ data.tar.gz: 6fdf6349dbd2644641d8ccc3aed7bb0716bf2b7f40545cf02dc7b3a4384dead4f197dd03e55fa8c6ee8e0b466d6987591f565b28a208dfcf8c2a346ae4bd9215
@@ -30,10 +30,11 @@ module Farcall
30
30
  abort :format_error, $!
31
31
  end
32
32
  }
33
- @send_lock = Mutex.new
34
- @receive_lock = Mutex.new
35
33
 
36
- @waiting = {}
34
+ @send_lock = Mutex.new
35
+ @receive_lock = Mutex.new
36
+ @handlers = {}
37
+ @waiting = {}
37
38
  end
38
39
 
39
40
  # The provided block will be called if endpoint functioning will be aborted.
@@ -123,14 +124,32 @@ module Farcall
123
124
  result
124
125
  end
125
126
 
126
- # Process remote commands. Not that provider have precedence at the moment.
127
- # Provided block will be executed on every remote command taking parameters
128
- # |name, args, kwargs|. Whatever block returns will be passed to a calling party.
129
- # The same any exception that the block might raise would be send back to caller.
127
+ # Process remote commands. Provided block will be executed on every remote command
128
+ # taking parameters |name, args, kwargs|. Whatever block returns will be passed to a calling
129
+ # party. The same any exception that the block might raise would be send back to caller.
130
+ #
131
+ # this block will be called onlly of there wes no `provider` specified and no #on handler set
132
+ # for the command being executed.
133
+ #
130
134
  def on_remote_call &block
131
135
  @on_remote_call = block
132
136
  end
133
137
 
138
+ alias on_command on_remote_call
139
+
140
+ # Set handler to perform the named command. Block will be called when the remote party calls
141
+ # with parameters passed from the remote. The block returned value will be passed back to
142
+ # the caller.
143
+ #
144
+ # The provider if set is calling instead.
145
+ #
146
+ # If the block raises the exception it will be reported to the caller as an error (depending
147
+ # on it's platofrm, will raise exception on its end or report error)
148
+ def on(name, &block)
149
+ @handlers[name.to_s] = block
150
+ end
151
+
152
+
134
153
  # Get the Farcall::RemoteInterface connnected to this endpoint. Any subsequent calls with
135
154
  # return the same instance.
136
155
  def remote
@@ -175,6 +194,8 @@ module Farcall
175
194
  args << fixed
176
195
  end
177
196
  @provider.send :remote_call, cmd.to_sym, args
197
+ elsif (h = @handlers[cmd.to_s])
198
+ h.call args, kwargs
178
199
  elsif @on_remote_call
179
200
  @on_remote_call.call cmd, args, kwargs
180
201
  end
@@ -1,3 +1,3 @@
1
1
  module Farcall
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -17,7 +17,7 @@ class TestProvider < Farcall::Provider
17
17
  end
18
18
 
19
19
  def get_hash
20
- { 'foo' => 'bar', 'bardd' => 'buzz', 'last' => 'item', 'bar' => 'test'}
20
+ { 'foo' => 'bar', 'bardd' => 'buzz', 'last' => 'item', 'bar' => 'test' }
21
21
  end
22
22
 
23
23
  private
@@ -33,7 +33,7 @@ class StringProvider < Farcall::Provider
33
33
  end
34
34
 
35
35
  def provide_hash
36
- { 'bar' => 'test', 'foo' => 'bar'}
36
+ { 'bar' => 'test', 'foo' => 'bar' }
37
37
  end
38
38
 
39
39
  def value
@@ -44,6 +44,21 @@ end
44
44
  describe 'endpoint' do
45
45
  include Farcall
46
46
 
47
+ it 'runs on commands' do
48
+ tc = Farcall::LocalConnection.new
49
+
50
+ ea = Farcall::Endpoint.new tc.a
51
+ eb = Farcall::Endpoint.new tc.b
52
+
53
+ ea.on('command_one') { |args, kwargs|
54
+ { 'return_one': [args, kwargs] }
55
+ }
56
+ rs = eb.remote.command_one("uno", 'due', tre: 3)
57
+ rs.return_one[0].should == ['uno', 'due']
58
+ rs.return_one[1].should == { 'tre' => 3}
59
+
60
+ end
61
+
47
62
  it 'should do RPC call with provider/interface' do
48
63
  tc = Farcall::LocalConnection.new
49
64
 
@@ -72,6 +87,7 @@ describe 'endpoint' do
72
87
  expect(-> { i.abort() }).to raise_error Farcall::RemoteError, /NoMethodError/
73
88
  expect(-> { i.doncallpublic() }).to raise_error Farcall::RemoteError, /NoMethodError/
74
89
  expect(-> { i.initialize(1) }).to raise_error Farcall::RemoteError, /NoMethodError/
90
+ expect(-> { i.endpoint.call(:class, 1) }).to raise_error Farcall::RemoteError, /NoMethodError/
75
91
  end
76
92
 
77
93
  def check_protocol format
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: farcall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergeych