Sha256: 4f878bc2be161b6b7ac2e111ac6185d9b4ca99b32f34e100bc604976fed54a85

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 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 }
        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

5 entries across 5 versions & 1 rubygems

Version Path
httpx-0.15.4 lib/httpx/plugins/grpc/call.rb
httpx-0.15.3 lib/httpx/plugins/grpc/call.rb
httpx-0.15.2 lib/httpx/plugins/grpc/call.rb
httpx-0.15.1 lib/httpx/plugins/grpc/call.rb
httpx-0.15.0 lib/httpx/plugins/grpc/call.rb