# 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