Class: HTTPX::Plugins::GRPC::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/plugins/grpc/call.rb,
sig/plugins/grpc/call.rbs

Overview

Encapsulates call information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Call

Returns a new instance of Call.

Parameters:



10
11
12
13
14
15
# File 'lib/httpx/plugins/grpc/call.rb', line 10

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object (private)



55
56
57
58
59
# File 'lib/httpx/plugins/grpc/call.rb', line 55

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

  super
end

Instance Attribute Details

#decoder=(value) ⇒ Object (writeonly)

Sets the attribute decoder

Parameters:

  • value (_Callable)

    the value to set the attribute decoder to.



8
9
10
# File 'lib/httpx/plugins/grpc/call.rb', line 8

def decoder=(value)
  @decoder = value
end

Instance Method Details

#grpc_responsegrpc_response

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/httpx/plugins/grpc/call.rb', line 37

def 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

#inspectObject



17
18
19
# File 'lib/httpx/plugins/grpc/call.rb', line 17

def inspect
  "#{self.class}(#{grpc_response})"
end

#metadataheaders

Returns:

  • (headers)


25
26
27
# File 'lib/httpx/plugins/grpc/call.rb', line 25

def 
  response.headers
end

#to_sObject



21
22
23
# File 'lib/httpx/plugins/grpc/call.rb', line 21

def to_s
  grpc_response.to_s
end

#trailing_metadataheaders?

Returns:

  • (headers, nil)


29
30
31
32
33
# File 'lib/httpx/plugins/grpc/call.rb', line 29

def 
  return unless @consumed

  @response.
end