Sha256: 1a0ccadfb82ddf2f58ae2a5c18a33249df2d4eb7f9658c99bfac99ac9ac5c28e

Contents?: true

Size: 1.38 KB

Versions: 55

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    module GRPC
      # Encapsulates call information
      class Call
        attr_writer :decoder

        def initialize(response)
          @response = response
          @decoder = ->(z) { z }
          @consumed = false
        end

        def inspect
          "#GRPC::Call(#{grpc_response})"
        end

        def to_s
          grpc_response.to_s
        end

        def metadata
          response.headers
        end

        def trailing_metadata
          return unless @consumed

          @response.trailing_metadata
        end

        private

        def grpc_response
          return @grpc_response if defined?(@grpc_response)

          @grpc_response = if @response.respond_to?(:each)
            Enumerator.new do |y|
              Message.stream(@response).each do |message|
                y << @decoder.call(message)
              end
              @consumed = true
            end
          else
            @consumed = true
            @decoder.call(Message.unary(@response))
          end
        end

        def respond_to_missing?(meth, *args, &blk)
          grpc_response.respond_to?(meth, *args) || super
        end

        def method_missing(meth, *args, &blk)
          return grpc_response.__send__(meth, *args, &blk) if grpc_response.respond_to?(meth)

          super
        end
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
httpx-1.1.4 lib/httpx/plugins/grpc/call.rb
httpx-1.1.3 lib/httpx/plugins/grpc/call.rb
httpx-1.1.2 lib/httpx/plugins/grpc/call.rb
httpx-1.1.1 lib/httpx/plugins/grpc/call.rb
httpx-1.1.0 lib/httpx/plugins/grpc/call.rb
httpx-1.0.2 lib/httpx/plugins/grpc/call.rb
httpx-0.24.7 lib/httpx/plugins/grpc/call.rb
httpx-1.0.1 lib/httpx/plugins/grpc/call.rb
httpx-1.0.0 lib/httpx/plugins/grpc/call.rb
httpx-0.24.6 lib/httpx/plugins/grpc/call.rb
httpx-0.24.5 lib/httpx/plugins/grpc/call.rb
httpx-0.24.4 lib/httpx/plugins/grpc/call.rb
httpx-0.24.3 lib/httpx/plugins/grpc/call.rb
httpx-0.24.2 lib/httpx/plugins/grpc/call.rb
httpx-0.24.1 lib/httpx/plugins/grpc/call.rb
httpx-0.24.0 lib/httpx/plugins/grpc/call.rb
httpx-0.23.4 lib/httpx/plugins/grpc/call.rb
httpx-0.23.3 lib/httpx/plugins/grpc/call.rb
httpx-0.23.2 lib/httpx/plugins/grpc/call.rb
httpx-0.23.1 lib/httpx/plugins/grpc/call.rb