Class: GrpcMock::GrpcStubAdapter::AdapterClass

Inherits:
GRPC::ClientStub
  • Object
show all
Defined in:
lib/grpc_mock/grpc_stub_adapter.rb

Overview

Instance Method Summary collapse

Instance Method Details

#bidi_streamer(method, requests, *args) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 58

def bidi_streamer(method, requests, *args)
  unless GrpcMock::GrpcStubAdapter.enabled?
    return super
  end

  r = requests.to_a       # FIXME: this may not work
  mock = GrpcMock.stub_registry.response_for_request(method, r)
  if mock
    mock.evaluate(r)
  elsif GrpcMock.config.allow_net_connect
    super
  else
    raise NetConnectNotAllowedError, method
  end
end

#client_streamer(method, requests, *args) ⇒ Object

TODO



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 27

def client_streamer(method, requests, *args)
  unless GrpcMock::GrpcStubAdapter.enabled?
    return super
  end

  r = requests.to_a       # FIXME: this may not work
  mock = GrpcMock.stub_registry.response_for_request(method, r)
  if mock
    mock.evaluate(r)
  elsif GrpcMock.config.allow_net_connect
    super
  else
    raise NetConnectNotAllowedError, method
  end
end

#request_response(method, request, *args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 11

def request_response(method, request, *args)
  unless GrpcMock::GrpcStubAdapter.enabled?
    return super
  end

  mock = GrpcMock.stub_registry.response_for_request(method, request)
  if mock
    mock.evaluate(request)
  elsif GrpcMock.config.allow_net_connect
    super
  else
    raise NetConnectNotAllowedError, method
  end
end

#server_streamer(method, request, *args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 43

def server_streamer(method, request, *args)
  unless GrpcMock::GrpcStubAdapter.enabled?
    return super
  end

  mock = GrpcMock.stub_registry.response_for_request(method, request)
  if mock
    mock.evaluate(request)
  elsif GrpcMock.config.allow_net_connect
    super
  else
    raise NetConnectNotAllowedError, method
  end
end