protobuf 3.6.10 → 3.6.11
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/protobuf/rpc/connectors/common.rb +1 -1
- data/lib/protobuf/rpc/middleware/exception_handler.rb +4 -0
- data/lib/protobuf/rpc/middleware/logger.rb +4 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +11 -16
- data/lib/protobuf/rpc/middleware/response_encoder.rb +15 -20
- data/lib/protobuf/rpc/service.rb +2 -10
- data/lib/protobuf/rpc/service_dispatcher.rb +7 -5
- data/lib/protobuf/rpc/service_filters.rb +8 -30
- data/lib/protobuf/version.rb +1 -1
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +3 -3
- 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: 6812ca2cb7f6dd5b3f0924e53439a512e13f0da7
         | 
| 4 | 
            +
              data.tar.gz: 56d57350ce7fc439d08ae6a14fff625477a03e56
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a928049ac386285aa71ac18393aca3e6cbfe781e6a5a3695218d129102e5a9ea6fc2f2e81e2705b5ede7dcb5aa0b75bcf37cb9c03007e2efc63406612e866b31
         | 
| 7 | 
            +
              data.tar.gz: a909a515c52c992147e98df9e72bcb985ce1098ebc271471d8138772587d52f1bd843506976bd010007dce6c56bece6ef3cda03aeba92f53981a3361f2442cd0
         | 
| @@ -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  | 
| 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 | 
            -
             | 
| 44 | 
            -
                       | 
| 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 ||=  | 
| 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 ||=  | 
| 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  | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 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 | 
            -
                       | 
| 66 | 
            -
             | 
| 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
         | 
    
        data/lib/protobuf/rpc/service.rb
    CHANGED
    
    | @@ -119,16 +119,8 @@ module Protobuf | |
| 119 119 | 
             
                    rpcs.key?(name)
         | 
| 120 120 | 
             
                  end
         | 
| 121 121 |  | 
| 122 | 
            -
                   | 
| 123 | 
            -
             | 
| 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 | 
            -
                     | 
| 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 | 
| 124 | 
            -
                       | 
| 125 | 
            -
             | 
| 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 | 
| 154 | 
            -
                       | 
| 155 | 
            -
             | 
| 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 | 
            -
                       | 
| 257 | 
            -
             | 
| 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
         | 
    
        data/lib/protobuf/version.rb
    CHANGED
    
    
| @@ -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. | 
| 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(: | 
| 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( | 
| 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. | 
| 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- | 
| 14 | 
            +
            date: 2016-08-15 00:00:00.000000000 Z
         | 
| 15 15 | 
             
            dependencies:
         | 
| 16 16 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 17 17 | 
             
              name: activesupport
         |