protobuf 3.6.10 → 3.6.11

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: 35210ca10c85eb3a8f769e223c53420c51d778ba
4
- data.tar.gz: 68cd7f756d8e2cacf66ba4bd28f4d51dd83419a9
3
+ metadata.gz: 6812ca2cb7f6dd5b3f0924e53439a512e13f0da7
4
+ data.tar.gz: 56d57350ce7fc439d08ae6a14fff625477a03e56
5
5
  SHA512:
6
- metadata.gz: a3d36aa1c336979c36ef24a3131d59c6013cdd4c87598b913155ab973ef2c9b9b88273c1f3b16a90a5c45d29728df9bd613c89f67d4c624604139553300f879b
7
- data.tar.gz: 81c975787fe88dc9eefd228931f02ed7cbedf8a90e75e9f97d5010570175c2d0500d1bfe7d1119f462fb5ffb8b2e5bd03c0d75b0a3d7038a3e0de49c4eaef786
6
+ metadata.gz: a928049ac386285aa71ac18393aca3e6cbfe781e6a5a3695218d129102e5a9ea6fc2f2e81e2705b5ede7dcb5aa0b75bcf37cb9c03007e2efc63406612e866b31
7
+ data.tar.gz: a909a515c52c992147e98df9e72bcb985ce1098ebc271471d8138772587d52f1bd843506976bd010007dce6c56bece6ef3cda03aeba92f53981a3361f2442cd0
@@ -119,7 +119,7 @@ module Protobuf
119
119
  def setup_connection
120
120
  initialize_stats
121
121
  @request_data = request_bytes
122
- @stats.request_size = request_bytes.size
122
+ @stats.request_size = @request_data.size
123
123
  end
124
124
 
125
125
  def succeed(response)
@@ -11,6 +11,10 @@ module Protobuf
11
11
  end
12
12
 
13
13
  def call(env)
14
+ dup._call(env)
15
+ end
16
+
17
+ def _call(env)
14
18
  app.call(env)
15
19
  rescue => exception
16
20
  log_exception(exception)
@@ -8,6 +8,10 @@ module Protobuf
8
8
 
9
9
  # TODO: Figure out how to control when logs are flushed
10
10
  def call(env)
11
+ dup._call(env)
12
+ end
13
+
14
+ def _call(env)
11
15
  instrumenter.start
12
16
  instrumenter.flush(env) # Log request stats
13
17
 
@@ -11,8 +11,13 @@ module Protobuf
11
11
  end
12
12
 
13
13
  def call(env)
14
+ dup._call(env)
15
+ end
16
+
17
+ def _call(env)
14
18
  @env = env
15
19
 
20
+ logger.debug { sign_message("Decoding request: #{env.encoded_request}") }
16
21
  env.service_name = service_name
17
22
  env.method_name = method_name
18
23
  env.request = request
@@ -33,22 +38,15 @@ module Protobuf
33
38
  private
34
39
 
35
40
  def method_name
36
- @method_name ||= begin
37
- method_name = request_wrapper.method_name.underscore.to_sym
38
-
39
- unless service.rpc_method?(method_name)
40
- fail MethodNotFound, "#{service.name}##{method_name} is not a defined RPC method."
41
- end
41
+ return @method_name unless @method_name.nil?
42
42
 
43
- method_name
44
- end
43
+ @method_name = request_wrapper.method_name.underscore.to_sym
44
+ fail MethodNotFound, "#{service.name}##{@method_name} is not a defined RPC method." unless service.rpc_method?(@method_name)
45
+ @method_name
45
46
  end
46
47
 
47
48
  def request
48
- @request ||= begin
49
- data = request_wrapper.request_proto
50
- rpc_method.request_type.decode(data)
51
- end
49
+ @request ||= rpc_method.request_type.decode(request_wrapper.request_proto)
52
50
  rescue => exception
53
51
  raise BadRequestData, "Unable to decode request: #{exception.message}"
54
52
  end
@@ -56,10 +54,7 @@ module Protobuf
56
54
  # Decode the incoming request object into our expected request object
57
55
  #
58
56
  def request_wrapper
59
- @request_wrapper ||= begin
60
- logger.debug { sign_message("Decoding request: #{env.encoded_request}") }
61
- Socketrpc::Request.decode(env.encoded_request)
62
- end
57
+ @request_wrapper ||= Socketrpc::Request.decode(env.encoded_request)
63
58
  rescue => exception
64
59
  raise BadRequestData, "Unable to decode request: #{exception.message}"
65
60
  end
@@ -11,6 +11,10 @@ module Protobuf
11
11
  end
12
12
 
13
13
  def call(env)
14
+ dup._call(env)
15
+ end
16
+
17
+ def _call(env)
14
18
  @env = app.call(env)
15
19
 
16
20
  env.response = response
@@ -41,32 +45,23 @@ module Protobuf
41
45
  # Prod the object to see if we can produce a proto object as a response
42
46
  # candidate. Validate the candidate protos.
43
47
  def response
44
- @response ||= begin
45
- candidate = env.response
46
- case
47
- when candidate.is_a?(Message) then
48
- validate!(candidate)
49
- when candidate.respond_to?(:to_proto) then
50
- validate!(candidate.to_proto)
51
- when candidate.respond_to?(:to_hash) then
52
- env.response_type.new(candidate.to_hash)
53
- when candidate.is_a?(PbError) then
54
- candidate
55
- else
56
- validate!(candidate)
57
- end
58
- end
48
+ return @response unless @response.nil?
49
+
50
+ candidate = env.response
51
+ return @response = validate!(candidate) if candidate.is_a?(Message)
52
+ return @response = validate!(candidate.to_proto) if candidate.respond_to?(:to_proto)
53
+ return @response = env.response_type.new(candidate.to_hash) if candidate.respond_to?(:to_hash)
54
+ return @response = candidate if candidate.is_a?(PbError)
55
+
56
+ @response = validate!(candidate)
59
57
  end
60
58
 
61
59
  # Ensure that the response candidate we've been given is of the type
62
60
  # we expect so that deserialization on the client side works.
63
61
  #
64
62
  def validate!(candidate)
65
- actual = candidate.class
66
- expected = env.response_type
67
-
68
- if expected != actual
69
- fail BadResponseProto, "Expected response to be of type #{expected.name} but was #{actual.name}"
63
+ if candidate.class != env.response_type
64
+ fail BadResponseProto, "Expected response to be of type #{env.response_type.name} but was #{candidate.class.name}"
70
65
  end
71
66
 
72
67
  candidate
@@ -119,16 +119,8 @@ module Protobuf
119
119
  rpcs.key?(name)
120
120
  end
121
121
 
122
- ##
123
- # Instance Methods
124
- #
125
- # Get a callable object that will be used by the dispatcher
126
- # to invoke the specified rpc method. Facilitates callback dispatch.
127
- # The returned lambda is expected to be called at a later time (which
128
- # is why we wrap the method call).
129
- #
130
- def callable_rpc_method(method_name)
131
- -> { run_filters(method_name) }
122
+ def call(method_name)
123
+ run_filters(method_name)
132
124
  end
133
125
 
134
126
  # Response object for this rpc cycle. Not assignable.
@@ -12,6 +12,10 @@ module Protobuf
12
12
  end
13
13
 
14
14
  def call(env)
15
+ dup._call(env)
16
+ end
17
+
18
+ def _call(env)
15
19
  @env = env
16
20
 
17
21
  env.response = dispatch_rpc_request
@@ -26,12 +30,10 @@ module Protobuf
26
30
 
27
31
  # Call the given service method.
28
32
  def dispatch_rpc_request
29
- unless rpc_service.respond_to?(method_name)
30
- fail MethodNotFound, "#{service_name}##{method_name} is not a publicly defined method."
31
- end
32
-
33
- rpc_service.callable_rpc_method(method_name).call
33
+ rpc_service.call(method_name)
34
34
  rpc_service.response
35
+ rescue NoMethodError
36
+ raise MethodNotFound, "#{service_name}##{method_name} is not a defined RPC method."
35
37
  end
36
38
 
37
39
  def method_name
@@ -120,15 +120,9 @@ module Protobuf
120
120
  # or an object that responds to `call`.
121
121
  #
122
122
  def invoke_via_if?(_rpc_method, filter)
123
- if_check = filter.fetch(:if) { ->(_service) { return true } }
124
- do_invoke = case
125
- when if_check.nil?
126
- true
127
- else
128
- call_or_send(if_check)
129
- end
130
-
131
- do_invoke
123
+ if_check = filter.fetch(:if, nil)
124
+ return true if if_check.nil?
125
+ call_or_send(if_check)
132
126
  end
133
127
 
134
128
  # If the target rpc endpoint method is listed in the :only option,
@@ -150,15 +144,9 @@ module Protobuf
150
144
  # or an object that responds to `call`.
151
145
  #
152
146
  def invoke_via_unless?(_rpc_method, filter)
153
- unless_check = filter.fetch(:unless) { ->(_service) { return false } }
154
- skip_invoke = case
155
- when unless_check.nil?
156
- false
157
- else
158
- call_or_send(unless_check)
159
- end
160
-
161
- !skip_invoke
147
+ unless_check = filter.fetch(:unless, nil)
148
+ return true if unless_check.nil?
149
+ !call_or_send(unless_check)
162
150
  end
163
151
 
164
152
  def rescue_filters
@@ -253,20 +241,10 @@ module Protobuf
253
241
  # __send__ assuming that we respond_to it. Return the call's return value.
254
242
  #
255
243
  def call_or_send(callable, *args, &block)
256
- return_value = case
257
- when callable.respond_to?(:call)
258
- callable.call(self, *args, &block)
259
- when respond_to?(callable, true)
260
- __send__(callable, *args, &block)
261
- else
262
- fail "Object #{callable} is not callable"
263
- end
264
-
265
- return_value
244
+ return callable.call(self, *args, &block) if callable.respond_to?(:call)
245
+ __send__(callable, *args, &block)
266
246
  end
267
-
268
247
  end
269
-
270
248
  end
271
249
  end
272
250
  end
@@ -1,3 +1,3 @@
1
1
  module Protobuf
2
- VERSION = '3.6.10'
2
+ VERSION = '3.6.11'
3
3
  end
@@ -29,7 +29,7 @@ RSpec.describe Protobuf::Rpc::ServiceDispatcher do
29
29
  before { allow(rpc_service).to receive(:response).and_return(response) }
30
30
 
31
31
  it "dispatches the request" do
32
- stack_env = subject.call(env)
32
+ stack_env = subject._call(env)
33
33
  expect(stack_env.response).to eq response
34
34
  end
35
35
 
@@ -42,10 +42,10 @@ RSpec.describe Protobuf::Rpc::ServiceDispatcher do
42
42
  end
43
43
 
44
44
  context "when the given RPC method is implemented and a NoMethodError is raised" do
45
- before { allow(rpc_service).to receive(:callable_rpc_method).and_return(-> { rpc_service.__send__(:foo) }) }
45
+ before { allow(rpc_service).to receive(:call).and_raise(NoMethodError) }
46
46
 
47
47
  it "raises the exeception" do
48
- expect { subject.call(env) }.to raise_exception(NoMethodError)
48
+ expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound)
49
49
  end
50
50
  end
51
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.10
4
+ version: 3.6.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - BJ Neilsen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-07-15 00:00:00.000000000 Z
14
+ date: 2016-08-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport