Sha256: 372622cb12b806ca622be540e6a4c0f8ae30f4c92f9ce638ebae40bf8d5e3f75

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

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

        def initialize(response, options)
          @response = response
          @options = options
          @decoder = ->(z) { z }
        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 @response.body.closed?

          @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
            end
          else
            @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

6 entries across 6 versions & 1 rubygems

Version Path
httpx-0.14.5 lib/httpx/plugins/grpc/call.rb
httpx-0.14.4 lib/httpx/plugins/grpc/call.rb
httpx-0.14.3 lib/httpx/plugins/grpc/call.rb
httpx-0.14.2 lib/httpx/plugins/grpc/call.rb
httpx-0.14.1 lib/httpx/plugins/grpc/call.rb
httpx-0.14.0 lib/httpx/plugins/grpc/call.rb