module ProtoPharm::GrpcStubAdapter::MockStub

Public Class Methods

allow_net_connect!() click to toggle source
# File lib/proto_pharm/grpc_stub_adapter/mock_stub.rb, line 11
def allow_net_connect!
  @allow_net_connect = true
end
allow_net_connect?() click to toggle source
# File lib/proto_pharm/grpc_stub_adapter/mock_stub.rb, line 15
def allow_net_connect?
  @allow_net_connect || false
end
disable_net_connect!() click to toggle source
# File lib/proto_pharm/grpc_stub_adapter/mock_stub.rb, line 7
def disable_net_connect!
  @allow_net_connect = false
end

Public Instance Methods

bidi_streamer(method, requests, *args) click to toggle source
Calls superclass method
# File lib/proto_pharm/grpc_stub_adapter/mock_stub.rb, line 71
def bidi_streamer(method, requests, *args)
  return super unless ProtoPharm.enabled?

  r = requests.to_a       # FIXME: this may not work
  request_stub = ProtoPharm.stub_registry.find_request_matching(method, r)

  if request_stub
    request_stub.received!(requests)
    request_stub.response.evaluate
  elsif _allow_net_connect?
    super
  else
    raise NetConnectNotAllowedError, method
  end
end
client_streamer(method, requests, *args) click to toggle source

TODO

Calls superclass method
# File lib/proto_pharm/grpc_stub_adapter/mock_stub.rb, line 40
def client_streamer(method, requests, *args)
  return super unless ProtoPharm.enabled?

  r = requests.to_a       # FIXME: this may not work
  request_stub = ProtoPharm.stub_registry.find_request_matching(method, r)

  if request_stub
    request_stub.received!(requests)
    request_stub.response.evaluate
  elsif _allow_net_connect?
    super
  else
    raise NetConnectNotAllowedError, method
  end
end
request_response(method, request, *args, return_op: false, **opts) click to toggle source
Calls superclass method
# File lib/proto_pharm/grpc_stub_adapter/mock_stub.rb, line 20
def request_response(method, request, *args, return_op: false, **opts)
  return super unless ProtoPharm.enabled?

  request_stub = ProtoPharm.stub_registry.find_request_matching(method, request)

  if request_stub
    operation = OperationStub.new(metadata: opts[:metadata]) do
      request_stub.received!(request)
      request_stub.response.evaluate(request)
    end

    return_op ? operation : operation.execute
  elsif _allow_net_connect?
    super
  else
    raise NetConnectNotAllowedError, method
  end
end
server_streamer(method, request, *args) click to toggle source
Calls superclass method
# File lib/proto_pharm/grpc_stub_adapter/mock_stub.rb, line 56
def server_streamer(method, request, *args)
  return super unless ProtoPharm.enabled?

  request_stub = ProtoPharm.stub_registry.find_request_matching(method, request)

  if request_stub
    request_stub.received!(request)
    request_stub.response.evaluate
  elsif _allow_net_connect?
    super
  else
    raise NetConnectNotAllowedError, method
  end
end

Private Instance Methods

_allow_net_connect?() click to toggle source
# File lib/proto_pharm/grpc_stub_adapter/mock_stub.rb, line 89
def _allow_net_connect?
  MockStub.allow_net_connect?
end